Процесс не может получить доступ к файлу 'C: \ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Временные файлы ASP.NET \ root \ 86edb30a \ dadba63b \ OCT.zip' - PullRequest
0 голосов
/ 24 декабря 2018

Когда я пытаюсь загрузить файл, я получаю следующую ошибку, не всегда некоторое время

Процесс не может получить доступ к файлу 'C: \ Windows \ Microsoft.NET \ Framework \ v4.0.30319\ Temporary ASP.NET Files \ root \ 86edb30a \ dadba63b \ OCT.zip ', поскольку он используется другим процессом.

Ниже приведен код, который я использую, может кто-нибудь сообщить мне, почемуэта ошибка идет.Заранее спасибо

 public static void LargeFile(string fileName, string filePath, string contentType)
        {
            Stream iStream = null;
            // Buffer to read 10K bytes in chunk
            //byte[] buffer = new Byte[10000];
            // Buffer to read 1024K bytes in chunk
            byte[] buffer = new Byte[1048576];

            // Length of the file:
            int length;
            // Total bytes to read:
            long dataToRead;

            try
            {
                fileName = GlobalComman.SplitFileName(fileName);

                // Open the file.
                iStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                // Total bytes to read:
                dataToRead = iStream.Length;
                HttpContext.Current.Response.ContentType = contentType;
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));

                // Read the bytes.
                while (dataToRead > 0)
                {
                    // Verify that the client is connected.
                    if (HttpContext.Current.Response.IsClientConnected)
                    {
                        // Read the data in buffer.
                        length = iStream.Read(buffer, 0, 10000);

                        // Write the data to the current output stream.
                        HttpContext.Current.Response.OutputStream.Write(buffer, 0, length);

                        // Flush the data to the HTML output.
                        HttpContext.Current.Response.Flush();

                        buffer = new Byte[10000];
                        dataToRead = dataToRead - length;
                    }
                    else
                    {
                        //prevent infinite loop if user disconnects
                        dataToRead = -1;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandlerTools.LogError(ex);
                // Trap the error, if any.
                //HttpContext.Current.Response.Write("Error : " + ex.Message);
                HttpContext.Current.Response.ContentType = "text/html";
                HttpContext.Current.Response.Write("Error : file not found");
            }
            finally
            {
                if (iStream != null)
                {
                    //Close the file.
                    iStream.Close();
                }
                HttpContext.Current.Response.End();
                HttpContext.Current.Response.Close();
            }
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...