I'm facing the following issue:
I have a C# asp.net file upload form with a submit button. After the form is submitted the file is uploaded and post-processing is started. The point is that the post-processing can take up to several minutes.
I would like to create some kind of asynchronous call of the post-processing function with showing information to the user.
So, the steps should be:
file form is submitted by user and upload is started
after the file is uploaded some information is shown to the user (e.g. "Processing..." or some loading-bar animation, etc.)
Meanwhile, the post-processing function is automatically started running in a background
After the post-processing function is finished the user is automatically redirected to another page
When i was searching the Internet I've found several examples but mostly only about asynchrounous call of functions, asynchrounous file upload (PageAsync method, etc.).
Any idea or techniques I should use or some tutorial?
Thanks in advance
That all depends on how fancy you want to get;
Meta-refresh that reloads the page until the background operation is finished
Some kind of ajax call that checks some resource for when the processing is done
HTML5 websockets. if supported, which it probably isn't.
Personally I would use the number 2. and use jQuery to poll the upload page every 500ms or something.
You can use AJAX
http://geekswithblogs.net/ranganh/archive/2008/04/01/file-upload-in-updatepanel-asp.net-ajax.aspx
http://vinayakshrestha.wordpress.com/2007/03/13/uploading-files-using-aspnet-ajax-extensions/
http://www.google.co.uk/search?sourceid=chrome&ie=UTF-8&q=upload+using+Ajax&qscrl=1#sclient=psy&hl=en&qscrl=1&source=hp&q=upload+using+Ajax+in+asp.net&aq=f&aqi=&aql=&oq=&pbx=1&fp=db9c4fafd449a821
The jquery/flash control uploadify will allow you to do this easily. They also provide a method for asynchronously calling a method on the event that the file upload completes as described in this comprehensive documentation.
I have looked at a lot of places for a good example, and this is the one I like the best so far.
It does not handle the uploading, but it does a fine job at showing real progress to the user and it is not difficult to implement
http://inov8.wordpress.com/2010/08/29/c-asp-net-creating-an-asynchronous-threaded-worker-process-manager-and-updatepanel-progress-monitor-control/
Related
Am fairly new to Web Development, and am currently building a website for client using Angular 5 front end, c# back end, using ASP.NET Core. The issue I'm having is I can pass the file and upload it, but want some way of tracking the upload process, as before I upload the file I run a whole bunch of formatting checks which can take anywhere between 10-15 minutes due to the size of the file.
Is there a way to have two HTTP requests, one which will start the process and return an indicator that the process has begun and another which can be called periodically from the front end, and provide a status update on the validating taking place.
Thanks in advance!
First of all - there is something wrong if you need to wait 15-20 minutes - you probably need to create separate work thread for this (Search for background work for asp.net core) and broadcast message to the clients after using something like SignalR.
About progress - JQuery deferred supports progress method. I believe there is an implementation for promises. And SignalR supports it as well.
Next, you need to implement it on the server side somehow like that
https://blogs.msdn.microsoft.com/dotnet/2012/06/06/async-in-4-5-enabling-progress-and-cancellation-in-async-apis/
Progress example:
https://www.codeproject.com/Articles/1124691/SignalR-Progress-Bar-Simple-Example-Sending-Live-D
Hope its enough to get started.
i'm searching for a way to upload huge files with jQuery and C#/VB.net (ASP).
I want to open an uploadform, select a file and upload it. After firing the upload (submit) it must be possible to leave the page with the upload form, and switching to another page within the same domain (Fire & Forget).
Can this be realized with jQuery and C# / VB.Net. On which Keywords i have to look to find a solution to get this working or is this impossible ?
Greetings
Marcus
You can use an async upload like following and then write a code to redirect a page.
http://www.dotnetjalps.com/2011/12/async-file-upload-with-jquery-and.html
at the end of process request method write following code.
context.Response.Redirect("YourPage.aspx");
i have a upload form in my web site, that allow the users to insert some items(usually trees), and they have the option to upload images after they added this items.
to upload image its take something like 15 second, but i want let the users the option to add another item in the time they are waiting for the image to upload.
so i want to use thread because:
after the upload will finish, the page will refresh and the form will reset, so they have to wait untill its will finish to upload if they want to add another item.
i tried this code:
protected void UploadFile(Object s, EventArgs e)
{
Thread t = new Thread(delegate()
{
//code for upload the image
)};
t.Start();
}
but its not working, and its even not uploading the file now.
some one know the reason?
thanks.
Your server side code is called only after the complete request is received.
So using a thread there won't help much.
If you want to keep your page interactive even while the upload happens you should look for an ajax based solution.
A very simple option is uploadify. You can hook it up to an HttpHandler and have your uploads happen in the background while the application remains interactive.
The chunk of time necessary to upload a file is not in the handling of it -- you are probably just saving the file somewhere -- it's the transmission of the file over the network.
So I would advise not to try to do background processing here, just handle it in the normal way, it will be just as performant. The user will just have to wait until the image is sent over the network.
If a user needs to add another item while his image is uploading, you can always let your site open another page in a tab/window on the browser.
maybe you can take a look at what HTML5 can do for you in terms of giving more feedback to the user that his file is been uploaded. Like Roy pointed out, transmission time is important and the users are going to have to wait anyway. But with HTML5 perhaps you can provide some nice progress bar to improve the user experience of your upload page.
Hope this helps.
I am trying to create a form which allow async file uploading with asp.net. I realize you cannot upload a file with ajax per se so I am examining alternatives
What is the best way to do this? Create an Iframe on the page with the entire form including the file input? Can I on the parent to the frame have the submit button which forces the frame to submit and then displays some sort of spinner to indicate file is uploading? Ideally upon completion I'd like to redirect the user to another page. Is there a somewhat easy way to do this???
Have you tried using one of the jquery plugins vice doing it by hand?
http://aquantum-demo.appspot.com/file-upload
Why not use the ASP.NET AJAX Control Toolkit's AsyncFileUpload control? It's free and works pretty well.
You could use http://jquery.malsup.com/form/#file-upload
Have it post to a page that will handle a file upload on the server side in your usual way.
I like to have the page return JSON with a success/failure flag and message, then parse the response to determine if the upload succeeded.
I need to develop a chat system in ASP.Net. I have gone through lots of SO question asked on similar topic, but did'nt find any one satisfactory. Is it possible to create it from scratch or do i need to go for some API's. My requirement is limited to my site users only, can say intranet based.
Please help me.
To make the text chat is one think that you can done with a simple table, everyone write on it, every one read time to time, and you show it to the page.
Here is an example http://www.codeproject.com/KB/ajax/ChatRoom.aspx
The Video/Audio chat is a complicate one. You can start with this example
http://www.codeproject.com/KB/IP/videochat.aspx
and you can read more here: how to work with videos in ASP.NET?
Text chat is relatively simple. It involves three tier architecture. 1) Javascript timer. 2) WCF Ajax Enabled web service or Generic Http Handler, 3) Data Storage (Preferably SQL).
1) On the page - sending: input text box + button (used to send). The button click event handler or the text box's key down (for enter key) and blur events would invoke a post (via JQuery, plain ol' JavaScript or whatever Javascript library you use) to the WCF service/Generic handler, sending the contents of the text box, along with the chartroom name, the addressee, and the recipient.
2) On the server: WCF Service/Generic Http handler receives the post and stores it in DB.
3) On the page - receiving: using JQuery for example, you would create a javascript timer on document ready (when the page loaded). On every timer's tick event you want to create a GET (or post) via your handy JavaScript framework (or Plain Javascript) to your WCF service/ Generic Handler requesting the latest records stored in the DB for that chatroom. Append the result received (assuming xml/html/json) to the Div or whatever element is used to display your "chats".
This is a very simplified chat in jquery/asp.net.
As far as audio-video is concerned, you have a few problems. 1) The browser itself has no means of interacting with the mike, speakers, and video camera, unless it uses a plugin. Moreover, browsers typically have no way of knowing how to decode a video stream (though some of the smarter ones have it built in... chrome, firefox). 3) Javascript has no way interacting with all the necessary hardware as it lives inside the browser.
All that said, you can use a plugin such as Flash or Silverlight, (that has built in access to the necessary hardware), or whatever. You will also have a conceptual dilemma with those as you have to simultaneously deal with 2 streams - one for coming in, another going out and displaying both. However it is possible.