Sunday, February 1, 2009

FileUpload.PostedFile.FileName and FileUpload.FileName

FileUpload.PostedFile.FileName = resolves to the complete path of the file including the filename you have selected to upload.

example: C:\temp\myFile.txt

FileUpload.Filename = is simply the name of the file you are uploading:

example: myFile.txt

to extract the extension you can use either for example you have FileUpload1 control on your form then you can do this:


string[] tempName = FileUpload1.FileName.Split('.');
Response.Write(tempName[tempName.Length-1]);

or

string[] tempName = FileUpload1.PostedFile.FileName.Split('.');
Response.Write(tempName[tempName.Length-1]);