我有他下面的代碼流或文件不打烊
HttpPostedFileBase files = Request.Files[0];
Stream fileStream = files.InputStream;
using (Stream file = System.IO.File.OpenWrite(originalImage))
{
StreamUtil.CopyStream(fileStream, file);
file.Close();
fileStream.close();
fileStream.dispose();
}
// here is CopyStream method
public static void CopyStream(Stream input, Stream output)
{
var buffer = new byte[8*1024];
int len;
while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, len);
}
}
當我嘗試寫同一個文件,我得到
The process cannot access the file \u0027D:FILENAME because it is being used by another process
我怎麼能收呢?因此一旦請求寫作完成後,它會被關閉?
什麼是'fileStream'?它從何而來? – Oded
更新了代碼,它來自請求。 – DarthVader
這是否會在每次嘗試再次寫入同一文件時發生?您是否嘗試使用[filemon](http://technet.microsoft.com/en-us/sysinternals/bb896642.aspx)查看哪個進程正在鎖定文件? – Oded