uploaded fles contenttype

Posted by Nishithraj under Regular Expressions on 1/28/2010 | Views : 3605 | Status : [Member] | Replies : 3
How to check the uploaded fles contenttype??

Ex: If I have a fileupload component named FileUpload1, I need to check whether it's an excel file. What would be the way??

Mark this as answer, if it is.....

With regards
Nishithraj Narayanan



Responses

Posted by: RtpHarry on: 1/28/2010 [Member] [MVP] Bronze

Up
0
Down
You would check the file extension to see if it matches a file type.

You can get the file extension out of a path by using the Path.GetExtension() method:

http://msdn.microsoft.com/en-us/library/system.io.path.getextension.aspx

Something like this:

Using System.IO;

// ...
string fileExt = Path.GetExtension(FileUpload1.FileName);
if(fileExt.Equals(".xls") || fileExt.Equals(".xlsx"))
{
// excel file type
}


Nishithraj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sagarp on: 1/29/2010 [Member] Bronze

Up
0
Down
ref this link


http://shawpnendu.blogspot.com/2009/05/file-upload-with-aspnet-c.html


thanks
sagar

Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Nishithraj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 1/29/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
use
FileUpload.PostedFile.ContentType

As easy like this. Now check this with "application/xls"

Cheers

www.abhisheksur.com

Nishithraj, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response