File.Delete()與過程的文件temp.jpg如果如何鎖定的過程B. 如何關閉處理文件temp.jpg如何刪除與進程的文件temp.jpg如果鎖定由進程B
IOExceoption: 因爲它正被另一個進程
protected void ButtonJcrop_Click(object sender, EventArgs e)
{
MembershipUser user = Membership.GetUser();
String tempPath = Server.MapPath("..") + @"\Users\" + user.ProviderUserKey.ToString() + @"\temp.gif";
System.Drawing.Image img = System.Drawing.Image.FromFile(tempPath);
Bitmap bmpCropped = new Bitmap(100, 100);
Graphics g = Graphics.FromImage(bmpCropped);
Rectangle rectDestination = new Rectangle(0, 0, bmpCropped.Width, bmpCropped.Height);
Rectangle rectCropArea = new Rectangle(Int32.Parse(hfX.Value), Int32.Parse(hfY.Value), Int32.Parse(hfWidth.Value), Int32.Parse(hfHeight.Value));
g.DrawImage(img, rectDestination, rectCropArea, GraphicsUnit.Pixel);
String mapPath = @"\Users\" + user.ProviderUserKey.ToString() + @"\" + user.ProviderUserKey.ToString() + ".gif";
bmpCropped.Save(Server.MapPath("..") + mapPath);
// bmpCropped.Save(Server.MapPath("..") + @"\Images\thumbs\CroppedImages\" + Session["WorkingImage"]);
imCropped.ImageUrl = Request.ApplicationPath + mapPath;
**File.Delete(tempPath);**
PlaceHolderImCropped.Visible = true;
}
的可能重複[我怎樣才能解開由在.NET進程鎖定的文件(http://stackoverflow.com/questions/242882/how-can-i-unlock- a-file-that-locked-by-a-process-in-net) – Ryan 2012-04-02 19:00:10