I edit pic file in path and create new image file for there.my code is:
string[] files = Directory.GetFiles(string.Concat(Server.MapPath("/"), "tmp/"));
foreach (string path in files)
{
string filename = Path.GetFileName(path);
using (Bitmap b = new Bitmap(string.Concat(Server.MapPath("/"), "tmp/", filename)))
{
SolidBrush pixelBrush = new SolidBrush(Color.White);
Graphics g = Graphics.FromImage(b);
g.FillRectangle(Brushes.White, 0, 0, 105, 40);
string outputFileName = string.Concat(Server.MapPath("/"), "tmp\\E", filename);
MemoryStream memory = new MemoryStream();
FileStream fs = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite);
b.Save(memory, ImageFormat.Jpeg);
byte[] bytes = memory.ToArray();
fs.Write(bytes, 0, bytes.Length);
fs.Close();
memory.Close();
b.Dispose();
}
File.Delete(path);
}
when delete old file error happend is:
Additional information: The process cannot access the file 'G:\project\WebApplication1\WebApplication1\tmp\b381ae6.jpg' because it is being used by another process.
how to fix it?