ASP.NET FileUpload caches files? - asp.net

I have a form with FileUpload control. Say, user chooses a file from his local disk, uploads it and then my site tells him that the file is in wrong format. The FileUpload control still retains the path to file.
Then the user makes neccessary corrections to his file and presses the upload button, assuming it will grab the updated version of his file. But the server still receives the old version of file, which is without user corrections! I even noticed that you can even rename or delete the local file after choosing it with FileUpload and it will still upload.
So my questions are:
Does FileUpload control cache files in some fashion?
Is this ASP.NET functionality or it's present in basic HTML control?
Can I remove this caching so that server always gets the latest version of the file?

Try using fileuploadId.Dispose() on pageload to clear the control.

Related

Uploadify onCancel event

I am using Uploadify plugin for asp.net web appication.
I want to let user delete an uploaded file. For this, I used onCancel event of Uploadify.
But, the problem is, if the page refreshes/postbacks, the FileUpload queue of Uploadify gets clear automatically.
How do I keep the queue-items as it is on Postbacks?
How do I delete files on server after they are automatically uploaded?
Do I need to write code in Upload.ashx or in codeBehind file of the webpage?
You need to store file upload status in database on file upload completion, at onCancel event just check (create handler with ajax call) whether there is already uploaded item stored, if yes then delete it.
There is no way to keep track of uploaded item once postback happen, all you need to store data in some sort of states (session, cookie) or in database.

Open File Dialog Asp.Net

I am creating an excel report in vb.net using the office interop. When the report is completed I am saving the excel file on the C drive. The users have asked to save file anywhere they want not just the c drive. Can someone give me some code to popup an opend file dialog in asp.net?
I want the dialog to popup in a saveAs in ASP.NET. I know how to do it in win forms, but I am creating an excel report in asp.net and calling the worksheet objects SaveAs property that excepts a fileName. So right now I just hardcode a file name in there. The users want to choose a file location
I think what you want is actually rather simple.
You can't save a file to the user's computer due to security restrictions (would you want a website saving a file to your computer?)
What you need to do is:
Complete report
Save report file to location on server, IE (.../myWebsite/files/GUID/myReport.rpt)
Display link on next screen pointing to the report file
Doing this the user can right-click and save the file to wherever they want on their computer.
You can clean up these files on whatever schedule you would like.
Assuming you are actually talking about a desktop, winforms app then you can use the built in FileSaveDialog.
Official documentation is here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.savefiledialog.aspx
but there are tons of tutorials explaining it out there:
http://www.google.co.uk/search?q=vb.net+savefiledialog
You can server files with the Open / Save dialog by using Response.TransmitFile().
The user is then presented with a save as dialog where they can choose the filename and the location on their computer.
You normally do this inside a HttpHandler. A simple one is described here:
http://blogs.msdn.com/petel/archive/2005/12/01/499189.aspx

ASP.NET File upload - Validation

In our application , we are using asp.net FileUpload control to upload files.
Requirement is , user should be able to upload only ".doc, .xls , .pdf" files.
System should not allow him to upload other files. To achieve this we are validating the extension of the uploaded file. If it is not valid then throwing error message.. this works fine..
But if i change the any exe file as .doc file , then system is allowing to upload. this should not happen.
Is there any way to validate the file with its content instead of its extension ..?
Check out this question/answer on stackoverflow. I belive this is a duplicate question.
Also, look into reading a file's magic number especially if you are just trying to determine if the file is one of a few acceptable types. Magic number Wikipedia
Uploadify is a good file uploading tool that I have found which allows you to specify which extensions you allow the user to see when uploading their files. It also has alot of other cool options and it is highly customizeable. It uses a combination of jquery and flash to allow the user to upload more than one file at a time as well (if desired).

How to upload pdf file into my own server?

In my site, user want to upload a pdf file and I have to save it into my own server. I don't need the content to be saved. I want the exact file to be copied into my server where the published file of the site exists.How to do this?
Use FileUpload Control and write code like
FileUpload1.PostedFile.SaveAs("Path and Filename");
You can easily use asp.net fileupload control: Uploading files in asp.net using C#
You can use ASP.NET file upload control which will handle this.You can mention where in your server you want to store it

ASP.NET FileUpload control not working inside Wizard control

I have a Wizard control with one of the pages containing a FileUpload control. I want to access the file stream at the point of the final page of the wizard but this doesn't seem to work.
As far as I can see, you can only access the file stream for the posted file on the postback which occurs immediately after the control has been used. As the file will ultimately be put into a DB record I could save it at this point, but I'd rather avoid this if possible.
Does anyone know of a workaround for this problem?
I've not used this control myself but as it's based around the HTML standard INPUT control I think you are stuck with having to receive the file on the post-back that processes that control.
The difficulty in circumventing this would be around how to pull the file from the client system when you are effectively sandboxed from the local filesystem, hence the need for the upload control.
I would suggest that you store the file into your DB blob (or as a temp file on the filesystem, probably need a unique filename; I find a GUID works nicely) and then use the Session object to retain that reference to the end of the process. The only other alternative I can think of that doesn't involve major work would be to move the file upload to the last page of your wizard.
You could have the displaying of your individual wizard stages managed client-side using CSS/jQuery rather than keep POSTing back to the server? That way, your only POST (resulting in the upload) will be at the end of the Wizard.

Resources