[英]c# convert fixed document to xps, but xps viewer will not open the new created xps file
i am trying to take a fixed document in c# and convert it to an xps and then save the xps so that i may attach it to an outlook email, but after i create the xps file and for testing purposes try to open the xps file in the xps file viewer, i get an error saying that the file cannot be opened, copy of the portion of the code where i am converting the fixed doc to an xps is pasted below: 我试图在c#中获取固定文档并将其转换为xps,然后保存xps,以便我可以将其附加到Outlook电子邮件中,但是在创建xps文件并出于测试目的后,请尝试在其中打开xps文件在xps文件查看器中,我收到一条错误消息,指出无法打开文件,我将固定文档转换为xps的部分代码的副本粘贴如下:
//save fixed document in temp directory as xps document
string filename = System.Environment.GetEnvironmentVariable("TEMP") + @"\TempFixedDocument.xps";
System.IO.File.Delete(filename);
XpsDocument xpsd = new XpsDocument(filename, FileAccess.ReadWrite);
XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(xpsd);
xw.WriteAsync(fxdDoc);
xpsd.Close();
I think it's because you use WriteAsync
, but not wait until writing is finished. 我认为这是因为您使用
WriteAsync
,而不是等到写入完成。 You should wait until file writing is finished and only then close the document. 您应该等待文件写入完成,然后再关闭文档。
You can use await keyword: 您可以使用await关键字:
await xw.WriteAsync(fxdDoc);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.