文件操作(增删查改)
1.删除
//url为图片的相对路径(~/UpLoadFiles/test.jpg),path为将url转换为绝对路径,通过File类操作
string path = HttpContext.Current.Server.MapPath(url); if (File.Exists(path)) { File.Delete(path); }
2.新建
以创建bmp(保存图片)为例
//新建bmp图片
//W,H为宽高,像素为单位
//path为相对路径(~/UpLoadFiles/t.jpg) System.Drawing.Bitmap timage = new System.Drawing.Bitmap(W, H);
try
{
//缩图图保存
timage.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception ex)
{
throw ex;
}
finally
{
timage.Dispose();
}