request.files adds the path on localhost
I'm using Request.Files to obtain a file that the user is uploading on my web page.
I noticed that if I use the filename property in IIS 开发者_如何学编程it gives me a path + filename, however if I run in cassini it only gives me the filename no matter what directory I use.
Why is this? And, is there a way to just use the filename when in IIS?
Thanks, rod.
To get the file name only use:
System.IO.Path.GetFileName(userPostedFile.FileName));
like:
HttpFileCollection uploadedFiles = Request.Files;
for (int i = 0; i < uploadedFiles.Count; i++)
{
HttpPostedFile userPostedFile = uploadedFiles[i];
if (userPostedFile.ContentLength > 0 )
{
string fileName = System.IO.Path.GetFileName(userPostedFile.FileName));
}
}
精彩评论