當我上傳圖像它顯示此錯誤,請你能幫助我嗎?上傳照片(因爲它正在被另一個進程使用)?
進程無法訪問文件'C:\ Websites \ telugufilmchance \ httpdocs \ User \ photo \ thumb \ PPTS00025sonali.jpeg',因爲它正在被另一個進程使用。 描述:執行當前Web請求期間發生未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。
異常詳細信息:System.IO.IOException:進程無法訪問文件'C:\ Websites \ telugufilmchance \ httpdocs \ User \ photo \ thumb \ PPTS00025sonali.jpeg',因爲它正在被另一個進程使用。
源錯誤:
if (ext == ".JPEG" || ext == ".JPG" || ext == ".PNG" || ext == ".BMP" || ext == ".GIF")
Line 193: {
Line 194: fupPhoto.PostedFile.SaveAs(path + filename);
Line 195: Bitmap src = Bitmap.FromStream(fupPhoto.PostedFile.InputStream) as Bitmap;
Line 196: Bitmap result = ResizeBitmap(src);
這是我的代碼(更新代碼,它是一個編輯頁面,我更新)
if (fupPhoto.FileName != string.Empty)
{
filename = ran(fupPhoto.FileName);
FileInfo fi = new FileInfo(filename);
string ext = fi.Extension.ToUpper();
string path = Server.MapPath("../User/photo/thumb/");
if (ext == ".JPEG" || ext == ".JPG" || ext == ".PNG" || ext == ".BMP" || ext == ".GIF")
{
fupPhoto.PostedFile.SaveAs(path + filename);
Bitmap src = Bitmap.FromStream(fupPhoto.PostedFile.InputStream) as Bitmap;
Bitmap result = ResizeBitmap(src);
SizeMgt(filename);
System.Drawing.Bitmap img = new System.Drawing.Bitmap(result, newwid, newhgt);
System.Drawing.Imaging.ImageCodecInfo jpegcodec = null;
System.Drawing.Imaging.EncoderParameters EncParams;
foreach (System.Drawing.Imaging.ImageCodecInfo codec in System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders())
{
if (codec.MimeType == "image/jpeg")
{
jpegcodec = codec;
break;
}
}
EncParams = new System.Drawing.Imaging.EncoderParameters(1);
EncParams.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 20L);
newfilename = "new" + filename;
img.Save(path + newfilename, jpegcodec, EncParams);
img.Dispose();
}
}
else
{
newfilename = myphot;
}
cmd = new SqlCommand("sp_uptreg", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@tregno", lblregno1.Text);
cmd.Parameters.AddWithValue("@catid", ddlCategory.SelectedItem.Value);
cmd.Parameters.AddWithValue("@fname", txtfname.Text);
cmd.Parameters.AddWithValue("@mname", txtmname.Text);
cmd.Parameters.AddWithValue("@lname", txtlname.Text);
cmd.Parameters.AddWithValue("@emailid", txtEmail.Text);
cmd.Parameters.AddWithValue("@phoneno", txtphone.Text);
cmd.Parameters.AddWithValue("@mobileno", txtMobile.Text);
cmd.Parameters.AddWithValue("@address", txtAdd.Text);
cmd.Parameters.AddWithValue("@photos", newfilename);
int a = cmd.ExecuteNonQuery();
我會檢查並通知你。感謝Aristos先生的回覆 – 2010-06-24 11:37:07