Reputation: 23
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:
//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();
Upvotes: 1
Views: 1810
Reputation: 87
I think it's because you use WriteAsync
, but not wait until writing is finished. You should wait until file writing is finished and only then close the document.
You can use await keyword:
await xw.WriteAsync(fxdDoc);
Upvotes: 1