This project has moved. For the latest updates, please go here.

How to handle “File Already Exists” scenario?

Jul 12, 2010 at 2:36 PM
Edited Jul 12, 2010 at 2:39 PM
I have the following requirements to prevent user from uploading duplicate files:

1 – File name can’t be changed. It has to be exact name provided by the user.
2 – User can’t upload file with the same name
3 – Throw an error or cancel upload if file exists but display “File Already Exists” instead of generic “Upload failed”

I know how to handle 1 and 2

What is the best way to handle #3?
Coordinator
Jul 12, 2010 at 3:33 PM
You'll need to have the HttpHandler respond some code or text or XML for example. Then read the response back in Silverlight and show your custom error message. Example: Response.ContentType = "text/xml"; Response.ContentEncoding = Encoding.UTF8; Response.Write( "<msg>duplicate</msg>"); Response.End();
Jul 12, 2010 at 4:19 PM
Edited Jul 12, 2010 at 4:19 PM
So I'll add

Response.ContentType = "text/xml";
Response.ContentEncoding = Encoding.UTF8;
Response.Write( "<msg>duplicate</msg>");
Response.End();

to the HttpHandler but what is the best place in your Uploader to read it?
Coordinator
Jul 12, 2010 at 4:26 PM

You can read the response of the HttpUploader in:

mpost.SilverlightMultiFileUpload.Core.HttpFileUploader: ReadHttpResponseCallback(IAsyncResult asynchronousResult)

It's a normal HttpHandler and a normal Http Request/Response. So you can find a bunch of info about that on the internet.

Good luck!