在我的点网程序中收到 'the process cannot access the file because it is being used by another process' 错误

getting an error that 'the process cannot access the file because it is being used by another process' in my dot net program

我试过 'using' 但它说该方法不是 Idisposable。我在任务管理器中检查了 运行 个进程,那里什么也没有。我的目标是将文件从本地目录上传到我网站的富文本编辑器。请帮我解决这个问题。提前致谢

public void OnPostUploadDocument()
{
    var projectRootPath = Path.Combine(_hostingEnvironment.ContentRootPath, "UploadedDocuments");
    var filePath = Path.Combine(projectRootPath, UploadedDocument.FileName);
    UploadedDocument.CopyTo(new FileStream(filePath, FileMode.Create));

    // Retain the path of uploaded document between sessions.
    UploadedDocumentPath = filePath;

    ShowDocumentContentInTextEditor();

}

private void ShowDocumentContentInTextEditor()
{
    WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
    Editor editor = new Editor(UploadedDocumentPath, delegate { return loadOptions; }); //passing path and load options (via delegate) to the constructor
    EditableDocument document = editor.Edit(new WordProcessingEditOptions()); //opening document for editing with format-specific edit options

    DocumentContent = document.GetBodyContent(); //document.GetContent();
    Console.WriteLine("HTMLContent: " + DocumentContent);

    //string embeddedHtmlContent = document.GetEmbeddedHtml();```
    //Console.WriteLine("EmbeddedHTMLContent: " + embeddedHtmlContent);
}

FileStream 是一次性的,所以你可以在上面使用:

using (var stream = new FileStream(filePath, FileMode.Create)
{
    UploadedDocument.CopyTo(stream);
}