我有一个文件上传代码,适用于谷歌浏览器但在IE中会抛出以下错误:
"IOException: 因为另一个进程正在使用该文件,所以无法访问路径\文件名。 System.IO.__Error.WinIOError(int errorCode, string maybeFullPath) System.IO.FileStream.Init(string path, FileMode mode, FileAccess access, int rights, bool useRights, FileShare share, int bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, string msgPath, bool bFromProxy, bool useLongPath, bool checkHost) System.IO.FileStream..ctor(string path, FileMode mode, FileAccess access, FileShare share) System.IO.File.OpenWrite(string path) RES.Controllers.DataHandling.DataUploadController+d__5.MoveNext() in DataUploadController.cs +"
下面是控制器操作方法:
请见下方视图模型:
我可以想象,代码应该没有问题,因为它在Chrome上运行正常。有人知道IE出了什么问题吗?
"IOException: 因为另一个进程正在使用该文件,所以无法访问路径\文件名。 System.IO.__Error.WinIOError(int errorCode, string maybeFullPath) System.IO.FileStream.Init(string path, FileMode mode, FileAccess access, int rights, bool useRights, FileShare share, int bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, string msgPath, bool bFromProxy, bool useLongPath, bool checkHost) System.IO.FileStream..ctor(string path, FileMode mode, FileAccess access, FileShare share) System.IO.File.OpenWrite(string path) RES.Controllers.DataHandling.DataUploadController+d__5.MoveNext() in DataUploadController.cs +"
下面是控制器操作方法:
public async Task<IActionResult> Upload(UploadedData data)
{
var filename=string.Empty;
if (ModelState.IsValid)
{
var file = data.File;
var parsedContentDisposition =
ContentDispositionHeaderValue.Parse(file.ContentDisposition);
filename = Path.Combine(_hostingEnvironment.ContentRootPath,
"UplaodedFiles", parsedContentDisposition.FileName.Trim('"'));
using (var stream = System.IO.File.OpenWrite(filename))
{
await file.CopyToAsync(stream);
}
}
}
请见下方视图模型:
public class UploadedData
{
public IFormFile File { get; set; }
}
我可以想象,代码应该没有问题,因为它在Chrome上运行正常。有人知道IE出了什么问题吗?
filename
是什么?请展示完整的[HttpPost] Upload
方法。 - jAC