Logo 
Search:

Asp.net Answers

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds
  Question Asked By: Holly Fox   on Apr 23 In Asp.net Category.

  
Question Answered By: Ginger Snyder   on Apr 23

This probably isn't the greatest solution, but you could determine your file
extentions in the following way:


string allowedFormats = "|gif|jpg|doc|txt|ppt|xls|htm|html|";
string x = "file.jpg";
Response.Write(x.Split(new char[] {'.'}, 2)[1] + "<br>");
if (allowedFormats.IndexOf("|" + x.Split(new char[] {'.'}, 2)[1] + "|") >
0 )
{
Response.Write("this extension is ok<br>");
}
else
{
Response.Write("this extension is NOT ok<br>");
}

string y = "file.jpg.ext";
Response.Write(y.Split(new char[] {'.'}, 2)[1] + "<br>");
if (allowedFormats.IndexOf("|" + y.Split(new char[] {'.'}, 2)[1] + "|") >
0 )
{
Response.Write("this extension is ok<br>");
}
else
{
Response.Write("this extension is NOT ok<br>");
}

The first filename, variable "x" - will print "this extension is ok" where
variable "y" will print "this extension is NOT ok"

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on upload file Or get search suggestion and latest updates.


Tagged: