Error in fileupload!

Posted by Coolbharat under ASP.NET on 1/7/2014 | Points: 10 | Views : 472 | Status : [Member] | Replies : 2
protected void btn_upload_Click(object sender, EventArgs e)
{
if (FileUpload_barcode_image.HasFile)
{
if (FileUpload_barcode_image.PostedFile.ContentType == "image/gif") //Check that only .gif images are uploaded.
{
if (FileUpload_barcode_image.PostedFile.ContentLength < 102400) //Check that Image size is below 1024 KB or 1 MB.
{
file_name = Path.GetFileName(FileUpload_barcode_image.FileName); //using System.IO;is needed for the "Path" .

//Delete Old file before uploading new file.
if (System.IO.File.Exists(Server.MapPath("~/UPLOAD IMAGE/") + file_name))
{
System.IO.File.Delete(Server.MapPath("~/UPLOAD IMAGE/") + file_name);
}
FileUpload_barcode_image.SaveAs(Server.MapPath("~/UPLOAD IMAGE/") + file_name);
lbl_upload_status.Text = "BarCode Image UPLOADED Successfully!";
}
else
{
lbl_upload_status.Text = "Please UPLOAD An Image of Size Less Than 1MB!";
}
}
else
{
lbl_upload_status.Text = "Please UPLOAD IMAGE of .gif extension only!";
}
}
else
{
lbl_upload_status.Text = "Please Choose An Image To UPLOAD!";
}
}


when first time i upload an image for processing the image to decode the barcode the result is fine.But when i upload the same image again it gives error that "The Process Can't access the file "location of image" because it is being used by another process."




Responses

Posted by: kgovindarao523-21772 on: 1/7/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,
I tried your code, but not getting any error when i upload the same image again.

Thank you,
Govind

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

Posted by: Coolbharat on: 1/7/2014 [Member] Starter | Points: 25

Up
0
Down
i tried the Garbage collection at the end of the code and it really solved my problem.Thanks Everybody for spending their precious time to take a look at my problem.

Thanks

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

Login to post response