FileStream can't access the file because it's being used by another process

后端 未结 2 1476
-上瘾入骨i
-上瘾入骨i 2021-01-20 16:12

I\'m new at web app in ASP.NET and I came across this problem.

I have a page whe there is a Button to download a template.xls that is previously stored at a SharePoi

2条回答
  •  野性不改
    2021-01-20 16:51

    From what I can tell, you're opening the file-stream, and then trying to open it again, before you close it.

    Initial opening of the file:

    FileStream _FileStream = new FileStream(apPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
    

    and

    Response.TransmitFile(apPath); 
    

    seems to be trying to open the file again.

    I would suggest calling

    _FileStream.Close();
    

    before calling TransmitFile.

提交回复
热议问题