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!
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!