Oct 23
So you’d think that uploading a file using the standard FileUpload control would be easy. Well there is a small problem. Using the following code you would expect ‘filename’ to contain just the filename of the file uploaded.
String filename;
filename = FileUpload1.PostedFile.FileName;
And you would be right, if you’re not using Internet Explorer which seems to think that the path of the file is important too so it includes that.
Here’s a simple solution to get around this
String filename;
filename =
System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
Now ‘filename’ will contain just the filename no matter which browser uploaded it.
This entry was posted
on Tuesday, October 23rd, 2007 at 12:52 pm and is filed under Programming, Rant, Snippet, Web Design.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
Leave a Comment