Upload while switching pages (C# jQuery) - c#

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");

Related

How to catch download link generated after buttonclick event

So as for input:
I am using C# and Selenium Webdriver to automate some verification on a website. Browser is IE9.
The steps that I am working on:
I have a table that was generated by ajax query. When I click print button it returns me a file to download that can be printed.
The issue that I need to catch the link to the file that is proposed for downloading and I have run out of ideas how to do that.
So I would be grateful to hear any advice of skilled users =).
Updated 08/01/14:
Ups sorry, I forgot to say that there is no link, actually button click triggers either a JS or ajax request that creates a document and then only then the link is generated and Open/Save IE dialog is displayed.
Updated
Link HTML
<a id="ucRadGrid_lnkPrintPDF" onclick="ucRadGrid.print();" href="javascript:__doPostBack('ucRadGrid','PDF')">
What i do, is i never allow my webdriver to manage a download. What i'll do is use pure C# to download the file for me.
You can do this simply by finding the link's href attr, and downloading that. Here is some pseudo-code:
var href = driver.FindElement(By.ID("download_link").GetAttribute("href");'
DownloadFile(href, "my file.ext");
From there, you can do what you need to. Validate the text using pure C#, etc.
EDIT After your comment below:
What you can to do is find the URL of the resource you want to download. That might require even playing around with the JS in the page. Find the function that downloads the file, and either execute that code, or parse through the function for the URL, and then execute DownloadFile

How to implement Blueimp jQuery file upload in ASP.NET

Trying to implement the Blueimp jQuery file uploader and am having a frustrating time making it work in my ASPNET MVC3 C# web-application. Its very difficult to determine which jquery and css includes are required (and which are not) when referring to the official documentation or Blueimp questions on this site.
Can anyone provide a working implementation of a bare-bones form containing a file input selector (not multiple files), a single "Upload" button, a single "Cancel" button, and a progress bar? After selecting a single file, clicking "Upload" should fire an AJAX call to "UploadFile" in FileController (which is already coded and working, and accepts an HttpPostedFileBase parameter) and update the progress-bar, without a form postback. There is also no requirement to add the file name to a list of files to be uploaded (as the Blueimp demo demonstrates), as the user will only be able to select a single file in this project.
Thanks to anyone kind enough to put me out of my misery on this one.
This should help you: https://github.com/maxpavlov/jQuery-File-Upload.MVC3
A clean and simple implementation of blueimp fileupload v5.9 in ASP.Net MVC 3

File upload that looks like ajax

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.

C# asp.net asynchronous function call after file is uploaded

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/

C# code for saving an entire web page? (with images/formatting)

I've been struggling to find an exmample of some C# code (I'm using C# Visual Studio 2008 Express) that can programmatically save an entire web page (given a URL) including the images and formatting (e.g. CSS). The intention is that in a subsequent phase I'd ship this off (not sure how yet) so it could be viewed later via a browser.
Is there an example of the most simple approach (leveraging the .NET Framework methods) to save an entire web page? Saving as one page with a subdirectory for images, or otherwise. Basically the same as what you get with browsers when you say "save entire web page".
The simplest way is probably to add a WebBrowser Control to your application and point it at the page you want to save using the Navigate() method.
Then, when the document has loaded, call the ShowSaveAsDialog method. The user can then save the page as a single file, or a file with images in a subdirectory.
[Update]
Having now noticed "programatically" in your question, the above approach is not ideal as it requires either user involvement or delving into the Windows API to send input using SendKeys or similar.
There is nothing built-in to the .NET Framework that does all of what you ask.
So my approach revised would be:
Use System.NET.HttpWebRequest to get the main HTML document as a string or stream (easy).
Load this into a HTMLAgilityPack document where you can now easily query the document to get lists of all image elements, stylesheet links, etc.
Then make a separate web request for each of these files and save them to a subdirectory.
Finally update all relevent links in the main page to point to the items in the subdirectory.
In effect you would be implementing a very simple web browser. You may run into issues with pages that use JavaScript to dynamically alter or request page content, but for most pages this should give acceptable results.
From code Project: ZetaWebSpider
It's definitely not elegant, but you could navigate a System.Windows.Forms.WebBrowser to the URL and then call its ShowSaveAsDiagog() method to save the page.

Categories

Resources