File Upload control
hi to all
i am trying to upload image file. inspite of no error in code it is going to exception and displaying error message of exception i am providing my code below
================================================
protected void btnUpLoad_Click(object sender, EventArgs e)
{
Boolean fileOK = false;
String path = Server.MapPath("~/UploadedImages/");
if (FileUpload1.HasFile)
{
String fileExtension =
System.IO.Path.GetExtension(FileUpload1.FileName). ToLower();
String[] allowedExtensions =
{ ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}
if (fileOK)
{
try
{
string uploadpath = path + FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(uploadpath);
Label1.Text = "File uploaded!";
}
catch (Exception ex)
{
Label1.Text = "File could not be uploaded.";
}
}
else
{
Label1.Text = "Cannot accept files of this type.";
}
}
================================================== ========
the above code in written under the button click called btnload:
it goes to exception ex and displays label1 message.
plz tell if any other setting or code is required
reply
thanks......
__________________
thanks......
|