1

我尝试了“使用”,但它说该方法不是 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);
}
4

1 回答 1

1

FileStream 是一次性的,因此您可以在其上使用 using:

using (var stream = new FileStream(filePath, FileMode.Create)
{
    UploadedDocument.CopyTo(stream);
}
于 2020-08-18T14:44:31.973 回答