Download file via Browser: used by another process

session101

Newcomer
Joined
May 10, 2006
Messages
23
I have a web app that I download file via the browser using this code:

Response.Clear();
Response.AddHeader("Content-Disposition",
"attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());

Response.ContentType = "application/vnd.ms-excel";

Response.Flush();
Response.WriteFile(file.FullName);
Response.End();



This works fine when the file is not opened by someone; otherwise, if a user has the file open on his machine, the web app will not launch the writefile function stating "file is used by another process". Is there a way to launch the file in read-only even though the file is already launched on a local client pc? TIA.
 
Not entirely sure where the problem lies? Are you getting the error because people are opening the .xls on their local machines or are they accessing the same .xls as the server is trying to download?
 
They are trying to access the same file that the app downloads locally onto their local machine.

This is scenario may help:
1.) One User opens xls file on local machine.
2.) Another user clicks button on application to open same xls file
- App downloads xls file to local temporary files folder of local machine
3.) App does not load file because of this error "fiel is used by another process"
- This occurs when I try to WriteFile()
 
Hi,

Did u find a solution to your problem? I have the same issue.
We have an asp.net UI to display log files (generated using log4net) to the user and the user can download the log file.
Response.WriteFile(FilePath); is used to download the file

If the log file is currently being written by a program then we are getting the error ""file is used by another process".

Any workarounds to this to be able to allow users to download the log files even though it is being currently written by another process ?

Thanks
 
Back
Top