|
-
Apr 13th, 2011, 08:21 AM
#1
Thread Starter
Hyperactive Member
The process cannot access the file (path) because it is being used by another process
I have a form with multiple FileUpload (around 8) and then i want to attach these uplaoded files to a message. The uplaoded files would be only images and i need to do some resizing of the image and for which i amusing a control aspJPEG. I am using below code and it works fine with IE but as soon as i try this code on another browser on MAC ,it gives me an error and some times on IE too
The process cannot access the file (path) because it is being used by another process.
how can i get away from this error. I am disposing object as well ,but please can some one check and see whats the matter ,or i have disposed objects at wrong place or i am missing some thing
any help would be appriciated. I am using Visual web developer 2010 with .net 4.0
if some body want to try it LIVE its here: http://www.taylorus.com/buyusedequip/
thanks
Code:
HttpFileCollection UploadFileCol = Request.Files;
for (int i = 0; i < UploadFileCol.Count; i++)
{
HttpPostedFile file = UploadFileCol[i];
if (file.ContentLength > 0)
{
strFileName = Path.GetFileName(file.FileName);
fullyqualifidespath = Server.MapPath("~/uploads/" + strFileName);
file.SaveAs(fullyqualifidespath);
file.InputStream.Dispose();
ASPJPEGLib.IASPJpeg objJpeg;
objJpeg = new ASPJPEGLib.ASPJpeg();
// Open source image
objJpeg.Open(fullyqualifidespath);
if (objJpeg.OriginalWidth > objJpeg.OriginalHeight)
{
objJpeg.Width = 400;
objJpeg.Height = objJpeg.OriginalHeight * objJpeg.Width / objJpeg.OriginalWidth;
}
if (objJpeg.OriginalWidth < objJpeg.OriginalHeight)
{
objJpeg.Width = 300;
objJpeg.Height = objJpeg.OriginalHeight * objJpeg.Width / objJpeg.OriginalWidth;
}
objJpeg.Save(fullyqualifidespath);
objJpeg.Close();
msg.Attachments.Add(new Attachment(fullyqualifidespath));
}
}
SmtpClient client = new SmtpClient("someserver.net", 25);
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(msg);
msg.Attachments.Dispose();
msg.Dispose();
Response.Redirect("thankyou.aspx");
Last edited by Kirun; Apr 13th, 2011 at 08:22 AM.
Reason: version info
-
Apr 14th, 2011, 02:09 AM
#2
Re: The process cannot access the file (path) because it is being used by another pro
I haven't checked the code, but going by the error message it sounds like concurrency problems with two things attempting to access the file at the same time. Windows will place a lock on a file when process1 accesses it and prevent process2 from writing to that file (modifying it). The solution would be to try and find where/when two different processes are trying to access the same file at the same time.
-
Apr 14th, 2011, 06:24 AM
#3
Re: The process cannot access the file (path) because it is being used by another pro
You can get these errors when saving a file and imediately trying to modify it. Even though you may dispose of everything I've noticed this can occure from time to time. The time interval between a few lines of code running are very small and IO/file conflicts in saving then opening a file
The way I work with uploaded images straight away is to create the image object from the fileUploadStream, no need to save it to disk, change it, save it elsewhere, and delete the redundant file.
I looked at ASPJPEGLib and it may be possible see here
http://www.aspjpeg.com/manual_02.html#2_3
The problem with computers is their nature is pure logic. Just once I'd like my computer to do something deluded. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|