Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i got this error "The process cannot access the file 'G:\ADMIN\Files\aaa.xlsx' because it is being used by another process" when i upload file to website:
below code:

VB
If FileUpload1.HasFile Then
            Dim Filename As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
            
            Dim FolderPath As String = ConfigurationManager.AppSettings("FolderPath")

            Dim Filepath as string = Server.MapPath(FolderPath + Filename)

            FileUpload1.SaveAs(Filepath) // error comes at this line 
Posted
Comments
[no name] 28-Sep-13 14:11pm    
Okay so use a different filename or close whatever process has the file open.
JoCodes 28-Sep-13 15:30pm    
Yes you have to check whether the file is already open , if so close and try uploading

If it is your code that has it open you can close it otherwise you may not be able to. The error is saying that you are trying to overwrite the file on the G drive but someone has it open. You should find out why someone has it open. Or, if it happens perhaps you could change the name of the file you are trying to save it as. But then you'll have a different copy.
 
Share this answer
 
There must be some excel file open which you are accessing through your code. You need to close that file before using in your code.
- SG
 
Share this answer
 
Comments
priyanshbhaliya 30-Sep-13 2:09am    
BUT when first time i upload it can't give any error but next time when i try to upload it gives an error and i directly open file is not open....

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