what is namespace for extension string

Posted by maninaanee-8287 under ASP.NET on 12/12/2011 | Points: 10 | Views : 1615 | Status : [Member] | Replies : 3
Actually iam copy the google code. I am getting error in extensionstring. once check my code
private void UploadFileUsingASPNET(FileUpload fileupload)
{
try
{
// check if file has been selected
if (FileUploadSingle.HasFile)
{
string path = Server.MapPath("~/MultipFileUpload/");
string fileName = Path.GetFileName(FileUploadSingle.PostedFile.FileName);
// check for the valid file
extensionstring fileExtension = Path.GetExtension(fileName).ToLower();
if (fileExtension.Equals(".gif") || fileExtension.Equals(".jpg"))
{
// now save the file to the disk
FileUploadSingle.SaveAs(path + fileName);
lblMessage.Text += "File : <b>" + fileName + "</b> uploaded successfully ! <br />";
}
else
{
lblError.Text = "Only .gif and .jpg files are allowed.";
}
}
else
{
lblError.Text = "Please select a valid file.";
}
}
catch (Exception ee)
{
lblError.Text = ee.Message;
}

}




Responses

Posted by: Jpchoudhari on: 12/12/2011 [Member] Starter | Points: 25

Up
0
Down
hi,

extensionstring fileExtension = Path.GetExtension(fileName).ToLower(); 


this code is used to find whether user has uploaded file with desired extension or not.

corrected code

string fileExtension = Path.GetExtension(fileName).ToLower();


here you will get file extension in variable fileExtension and later this is used in if case rest the things are correct.


Kind Regards,
Jay

maninaanee-8287, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bees7000 on: 12/12/2011 [Member] Starter | Points: 25

Up
0
Down
FileInfo f=new FileInfo(filePath);
Response.Write(f.Extension);

Marwan

maninaanee-8287, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 12/13/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,
your statement is
// check for the valid file 

extensionstring fileExtension = Path.GetExtension(fileName).ToLower();

rewrite this statement as
// check for the valid file extension

string fileExtension = Path.GetExtension(fileName).ToLower();


this will resolve issue

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

maninaanee-8287, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response