Cant Access File because it is being used by another process

前端 未结 6 2137
我寻月下人不归
我寻月下人不归 2020-12-11 09:25

I have an ASP.NET program where i am downloading a file from web using DownloadFile method of webClient Class and the do some modifications on it. then i am Saving it to ano

6条回答
  •  粉色の甜心
    2020-12-11 10:19

    try the following, set your filestream to Asynchronus mode (3rd parameter)

    FileStream myStream = File.Create(fileName, results.Length,FileOptions.Asynchronous);
    //make sure you close the file
    myStream.Write(results, 0, results.Length);
    myStream.Flush();
    myStream.Close();
    myStream.Dispose();
    

    if this fails reset the attributed of the file b4 you access it

    File.SetAttributes(Server.MapPath(sendFilepath), FileAttributes.Normal);
    

提交回复
热议问题