Click here to Skip to main content
15,039,037 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
getting the following error during saving a uploaded file into folder.
The process cannot access the file because it is being used by another process.



here is the code em using
C#
string CompanyName = (InsertItem.FindControl("txbName") as RadTextBox).Text;
        string CompanyAddress = (InsertItem.FindControl("txtAddress") as TextBox).Text;
        string ContactPerson = (InsertItem.FindControl("txtContactPerson") as TextBox).Text;
        int PhoneNumber = int.Parse((InsertItem.FindControl("txtPhoneNumber") as TextBox).Text);
        string EmailID = (InsertItem.FindControl("txtEmail") 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);
        //UploadedFile file = radAsyncUpload.UploadedFiles[0];
        string s = file.FileName;
        string path = System.IO.Path.GetFileName(s);
radAsyncUpload.UploadedFiles[0].SaveAs(Server.MapPath(path));

the line causing error is..
C#
radAsyncUpload.UploadedFiles[0].SaveAs(Server.MapPath(path));
Posted
Updated 26-Aug-11 2:46am
v4

Is the below code required in your logic?
ASM
byte[] fileData = new byte[file.InputStream.Length];
file.InputStream.Read(fileData, 0, (int)file.InputStream.Length);


I don't think you are using the input stream anywhere after this code.
Please comment it and try again.
   
Comments
aa8716 26-Aug-11 9:43am
   
Thanks for ur reply, the first line is required in logic becuase i need to convert image file into byte code as em inserting the image into database.. I have commented the second and error is not coming now thanks for that too.. further pls help me in storing the image into folder..The same line of code which i pointed as error causing in my question is needed for storing image into folder .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900