Cleaning File Name

Jul 7, 2010 at 2:49 PM
Edited Jul 7, 2010 at 2:58 PM

I have an issue with users uploading files with an ampersand & in the file name. This causes the querystring to be mangled and everything after the & is left out of the file name, including file extension. Is there a best way/place to remove this before it goes into the HttpContext? Thanks.

Jul 22, 2010 at 9:03 PM
This has been fixed in the latest code. Note that the new source code and examples are a visual studio 2010 project whereas the old one was a 2008 project.
Jul 26, 2010 at 2:02 PM
Edited Jul 26, 2010 at 2:26 PM

Downloaded the newest code and swapped the line where you UrlEncode the file name. I did not see any other changes that affect my code.

Problem now is, the file extension is still not being passed if & or # is included in the filename. Your test example sends bad characters through the userContext, but my issue is in the file name specifically. I need to remove all illegal characters (my definition or .NETs) but keep all the text. I have tried several different scenarios and still not getting the QueryString to write correctly. Using UrlEncode I believe these values are being interpreted correctly.

My test file name is test&file#name.txt. It should correct to something like testfilename.txt. What I end up getting is filename=test and null values for context and processor, which return an {"Object reference not set to an instance of an object."}. My application requires the userContext variables. I attempted re-arranging the order of the QueryString in the same code block so as to write the processor and usercontext first, but its not taking?

Another file name, test&file&name.txt returns filename=test without an extension as "file" and "name" are treated as parameters and .txt is ignored.

As mentioned, I've tried a number of workarounds but my knowledge of Silverlight is very very beginner. Thanks so much for your help, I love the control, and I am learning a lot about Silverlight in this process. Thanks!


Jul 26, 2010 at 4:38 PM
I specifically tested the file names as well -- my test file name was "test & stuff.txt". Encoding the file name took care of the & and spaces just fine in my tests...
Jul 26, 2010 at 7:07 PM
I trashed all my files and restarted with your latest build and re-did my modifications. All works well. Thanks!