Can we assign file extension using FileUpload

G

Guest

What exactly are you trying to do and why?

Tell us more about what you want to accomplish, there may be a better/easier
way.

-KF
 
M

Mark Rae

I want to uer upload a excel file, I want to limit the file extension to
".xls"

protected HtmlInputFile txtFileName;

if(Path.GetExtension(txtFileName.PostedFile.FileName) != ".xls"
{
// do something
}
 
A

ad

I have tried the RegularExpressionValidator , but no effect!


Sreejith Ram said:
you can use a asp:RegularExpressionValidator to validate file extensions

a sample regular expression for XSL and CSV is

^[0-9A-Za-z_ ]+(.[xX][lL][sS]|.[cC][sS][vV])$

i am not good in regular exps, following site got lot of samples

http://www.regexlib.com/REDetails.aspx?regexp_id=259







Mark Rae said:
protected HtmlInputFile txtFileName;

if(Path.GetExtension(txtFileName.PostedFile.FileName) != ".xls"
{
// do something
}
 
G

Guest

Well, the reason could be that the Regular expression you are using is wrong.
You may want to test the expression with a RegularExpression tester to see
if it works.

I have used RegularExpressionValidator with file upload , in the past and it
used to work. Do not have access to the code now to post sample



ad said:
I have tried the RegularExpressionValidator , but no effect!


Sreejith Ram said:
you can use a asp:RegularExpressionValidator to validate file extensions

a sample regular expression for XSL and CSV is

^[0-9A-Za-z_ ]+(.[xX][lL][sS]|.[cC][sS][vV])$

i am not good in regular exps, following site got lot of samples

http://www.regexlib.com/REDetails.aspx?regexp_id=259







Mark Rae said:
I want to uer upload a excel file, I want to limit the file extension to
".xls"

protected HtmlInputFile txtFileName;

if(Path.GetExtension(txtFileName.PostedFile.FileName) != ".xls"
{
// do something
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top