Uploadify onCancel event - asp.net

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.

Related

ASP.NET FileUpload caches files?

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.

Script in .ASP to create new page on server

I want to make an ASP script that can create a new page on the webserver and tell it what content that will be in the new .asp file.
How can i do that? :)
What you want to do is not to create a new page for each request. Instead you want to pre-create an ASP page that dynamically ouputs the a file based on the input of the user.
In your example of uploading a file to display. What you probably want to do is store the uploaded file somewhere and then create another ASP page that reads in the uploaded file and displays it using Response.binarywrite or response.write. Don't create a new ASP page for each uploaded file.
So for the sake of example, you would create an ASP script called "DisplayUploadedFile.asp" the code inside it would read in the file (wherever you are storing it on the server (for example in a DB) and then write it back out. The users would hit the same page regardless of which uploaded file they wanted to see with a parameter telling the script which to display. For example DisplayUploadedFile.asp?fileID=12
CAUTION: It is extremely dangerous security-wise to let users upload content that is displayed to other users. Don't do this unless you understand at a very high level what steps are necessary to make this functionality secure. Based on your question, I think it might be prudent to get a more senior programmer to review your solution before you publish it.

Using ASP.NET handler to upload files

I am using Plupload for multiple file uploads. The files are sent to a ashx handler which saves them. However, I also have a Fileupload control for users who do not have flash or javascript enabled. I am wanting to use the Handler to also handle uploads from the fileuplaod control so all my logic is kept in one place. Does anyone know if it is possible to send the file from the fileupload control to a handler?
Thanks in advance
I am not sure about how the fileupload control works. But you can try to create a workaround and have your logic in one place i.e to create a class that handles the uploaded file. Now both your handler and fileupload control will use this class to do the necessary with your files.

Flash uploader and ASP.net MVC

I have a flash upload component I want to use to upload multiple files. I'm using it in a MVC app and what I want to happen is that the user picks the files they want to upload, it uploads them and then displays a page showing all the files they have uploaded so they can add a description and select where to save them, and then save the files.
At the moment when files are uploaded the flash component calls a controller to process the files, this bit works fine, I can get the uploaded files and do what I like with them. The problem is is that I cannot just redirect to a View once the controllers done its work, because its the flash component calling the controller, not the page and so nothing happens when you try and do that.
I had attempted to save the files in the session and then forward the user on completion of the upload using some code in the flash actionscript, this however does not work, the session always turns up null. I had also considered actually saving the files to a temp location and then on the displaying page just listing all files in the temp location, but this is then going to involve saving the files twice, once to the temp directory and then to the actual place the user wants to put them, which I assume will be slow.
Any thoughts on the best way to do this?
Is your site using cookie based authentication? If so then the flash uploader needs to include the authentication cookie when uploading otherwise the upload will be seen as coming from a new user - this would explain your null values in the session state. If you are unable to get flash to post the cookie then you'll have to identify the user within the upload URL.
You should keep session state to a minimum or even better not use is at all so storing large amounts of data such as images in it is a bad idea.
With our applications we save all uploaded files to the database and then give them a unique Guid that is then used to retrieved/display them later. Within the database images could be associated with a user and in your case be marked as just uploaded so that when you redirect the user to the additional information page you know which images to display.
but this is then going to involve
saving the files twice, once to the
temp directory and then to the actual
place the user wants to put them
In relation to where the files are saved on the server you should not be allowing the user to determine where the files are saved.

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