The process cannot access the file because it is being used by another process. [Resolved]

Posted by A4u_6178 under ASP.NET on 8/26/2011 | Points: 10 | Views : 6435 | Status : [Member] | Replies : 2
Hello,

protected void RadGrid_Insert(object sender, GridCommandEventArgs e)
{
GridEditFormInsertItem InsertItem = e.Item as GridEditFormInsertItem;
try
{
string Name = (InsertItem.FindControl("txbName") as TextBox).Text;
RadAsyncUpload radAsyncUpload = InsertItem.FindControl("AsyncUpload1") as RadAsyncUpload;
UploadedFile file = radAsyncUpload.UploadedFiles[0];
byte[] fileData = new byte[file.InputStream.Length];
file.InputStream.Read(fileData, 0, (int)file.InputStream.Length);
string s = file.FileName;
string path = "images/";
BDL pBD = new BDL();
pBD.Insert_Employee(Name, fileData);
//Refersh Grid..
PopulateRadGrid();
file.InputStream.Close();
fileData = null;
file.InputStream.Dispose();
UploadedFile file1 = radAsyncUpload.UploadedFiles[0];
file1.SaveAs(Server.MapPath(path+s));
}

Line causing error when i checked in debug mode..
UploadedFile file1 = radAsyncUpload.UploadedFiles[0];
file1.SaveAs(Server.MapPath(path+s));

Any help is much appericiated.

Thanks & Regards,


Responses

Posted by: SheoNarayan on: 8/26/2011 [Administrator] HonoraryPlatinum | Points: 50

Up
0
Down

Resolved
This may happen because you are going to overwrite the file, upload every file with different different name, it should work fine.

As the name suggest, the file in question is not free to be used by another processor that is why you are getting this error. One more thing is that make sure that the process or object that is used to upload the file is being closed and disposed one the file is uploaded successfully.

This should help you.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

A4u_6178, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A4u_6178 on: 8/27/2011 [Member] Starter | Points: 25

Up
0
Down
HI Sir,

Thanks for ur reply..

resolved error like this..
protected void RadGrid_Insert(object sender, GridCommandEventArgs e)

{
GridEditFormInsertItem InsertItem = e.Item as GridEditFormInsertItem;
try
{
string Name = (InsertItem.FindControl("txbName") as TextBox).Text;
RadAsyncUpload radAsyncUpload = InsertItem.FindControl("AsyncUpload1") as RadAsyncUpload;
UploadedFile file = radAsyncUpload.UploadedFiles[0];
byte[] fileData = new byte[file.InputStream.Length];
file.InputStream.Read(fileData, 0, (int)file.InputStream.Length);
string s = file.FileName;
string path = "images/";
BDL pBD = new BDL();
pBD.Insert_Employee(Name, fileData);
//Refersh Grid..
PopulateRadGrid();

Update:
radAsyncUpload.UploadedFiles[0].SaveAs(Server.MapPath(path+s));





Thanks & Regards,

A4u_6178, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response