System.drawing.image can't delete file

Joined
Aug 14, 2010
Messages
1
Reaction score
0
Hi
I can't delete a file when it on the server, however I able to delete when it local, on my pc all works fine.
I"m uploading a file to my webserver and then resizing it, but unable to delete it after resizing.
here is the code:

if (FileUpload1.HasFile)
{
//uploading file
FileUpload1.SaveAs(Server.MapPath("images/images/" + FileUpload1.FileName));
LabelFile.Text = "Received " + FileUpload1.FileName + " Content Type " + FileUpload1.PostedFile.ContentType + " Length " + FileUpload1.PostedFile.ContentLength;
string sFileName = FileUpload1.FileName;

//resizing the uploaded file to s smaller size
using (System.Drawing.Image bm = System.Drawing.Image.FromFile(Server.MapPath("images/images/" + sFileName)))
{
Bitmap resized = new Bitmap((int)(0.5f * bm.Width), (int)(0.5f * bm.Height));
Graphics g = Graphics.FromImage(resized);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(bm, new Rectangle(0, 0, resized.Width, resized.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel);
bm.Dispose();
MemoryStream memStream = new MemoryStream();
resized.Save(memStream, ImageFormat.Jpeg);
resized.Dispose();
g.Dispose();

byte[] data = memStream.ToArray();
FileStream fstream = new FileStream(Server.MapPath("images/images/" + sFileName), FileMode.Open);
fstream.Write(data, 0, data.Length);

memStream.Close();
memStream.Dispose();
fstream.Close();
fstream.Dispose();
}
}


Thanks!
 

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,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top