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
Related
I would try to load in my ASP.NET Core 2.1 web application, some little pieces of views dynamically from a text file. This will allow me to load some specialized DIVs at runtime. Is there a way to make it runs or is a wrong way?
Thank you
You 'can' do this by loading the text file contents into a string, then using the #Html.Raw directive to 'output' the HTML to the webpage.
However, you may want to consider if this is really the best method for achieving what you want. Text files and their loading can be both slow and rather insecure (wouldn't want someone opening the text file up in notepad and typing an offensive message for example).
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 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 would like to write a Web Application that would have two buttons and directly from the browser would allow me to open two simple text files (using a File Open dialog box or something similar) and would then proceed to read in contents of those files and store them inside of a two strings. The key point here is that the exact files used to read from I don't known at runtime so it would be up to the user to select the files.
The goal is to be able to later compare those two strings but that part I already know how to do. My questions is this - is it even possible to do this inside of a Web Application (i.e. to call a File Open dialog box to allow the user to select files to read from) or would security limitations or some other Web Application related constraints prevent it from being done?
If it is possible, I would appreciate some sample code describing how to open files and how to read in contents of the selected files into strings. Othwerwise, I would like to know if it's not possible and I should consider doing a desktop application or try an entirely different way.
Thank you!
It is possible, but you would wind up having to upload both of the text files to the server and read the files into strings server-side.
All you would need to do is add two separate FileUpload controls to the page along with a button to post the files to the server.
If you don't want the page to refresh, you could always do the comparison via AJAX using the AsyncFileUpload control from the ASP.NET AJAX Toolkit.
Update
Reading the contents of the file should be relatively easy (as long as they are plain text):
var reader = new StreamReader(fileUploadControl.PostedFile.InputStream);
var contents = reader.ReadToEnd();
One way is to use the ASP.NET AJAX AsyncFileUpload control.
http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/AsyncFileUpload/AsyncFileUpload.aspx
In order to access the files from the server-side code (C# code) you'll need the user to upload them. The standard way to do this (and, for security reasons, the only way upon which you should rely) is with a file input element. In ASP.NET, you can use the FileUpload control.
You would essentially give the user two of these controls with which they can upload the two files. Then you'd read their contents on the server, save them however you wish (as files, to a database, just in Session for temporary use, etc.) and perform your logic on that data. Then build your output (the comparison part, which you said you have already) to display on the page refresh.
Be mindful of concerns such as what to do if the user tries to upload non-text files, very large files, etc.
That is not possible alone with JS. You would have to build a file upload (and store session information) or use Silverlight and a Javascript-Bridge to your Web-Application.
Here's an example for a FileOpenDialog in Silverlight: http://www.silverlightexamples.net/post/Open-File-Dialog-in-Silverlight.aspx
Here's an exmaple for a file upload via C#/Webforms http://support.microsoft.com/kb/323246
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.