What Was I Thinking?

Follies & Foils of .NET Development
posts - 77, comments - 203, trackbacks - 0

My Links

News

Archives

Post Categories

Check These Out

Gurus

QuickTip: Don’t rely on HTTPPostedFile.FileName

Supposedly, HTTPPostedFile.FileName is supposed to contain just the name of the uploaded file.  It should exclude the original filename path.  This doesn’t always appear to be the case, and seems to vary by the  browser doing an upload.

 

To avoid the browser issue entirely, use a FileInfo(HttpPostedFile.FileName) to return just the file name (and extension) portion of the file.

 

Change this:

Code Snippet
  1. var saveFileName = Path.Combine(UploadedFileServerPath, FilePackage.PostedFile.FileName);

to this:

Code Snippet
  1. var saveFileName = Path.Combine(UploadedFileServerPath, new FileInfo(FilePackage.PostedFile.FileName).Name);

Print | posted on Friday, November 05, 2010 8:57 PM | Filed Under [ Visual Studio ]

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: