I have very simple test where I am opening DOCX document by using FileStream and saving it.
When I try to open this document afterwards Word 2013 is saying that there is a problem and it can try to fix it.
Why is this?
In debug folder you have also DOC document where save works ok.
Sample project is attached.
Source code is:
public void OpenSave()
{
String path = "book1.docx";
FileStream fs = new FileStream(path, FileMode.OpenOrCreate);
Aspose.Words.Document doc = new Aspose.Words.Document(fs);
Aspose.Words.SaveFormat savFor = SaveFormat.Docx;
String extension;
extension = System.IO.Path.GetExtension(path);
switch (extension.ToLower())
{
case ".doc":
savFor = Aspose.Words.SaveFormat.Doc;
break;
case ".docm":
savFor = Aspose.Words.SaveFormat.Docm;
break;
case ".docx":
savFor = Aspose.Words.SaveFormat.Docx;
break;
case ".dot":
savFor = Aspose.Words.SaveFormat.Dot;
break;
case ".dotm":
savFor = Aspose.Words.SaveFormat.Dotm;
break;
case ".dotx":
savFor = Aspose.Words.SaveFormat.Dotx;
break;
}
doc.Save(fs, savFor);
fs.Dispose();
}
thanks, this helped.
I have to admit that I am confused - when I try to do Open/Save of .DOC file (my original coding) this works without problems. Saved document can be opened. With .DOCX this does not work.
Second is this not a performance issue:
open FileStream
close FileStream
open again same FileStream (I need to save in same document)
close FileStream
Why is there difference between .DOC and DOCX saving when using FileStream?
Thanks for your inquiry. As you are saving the output document to disk, I suggest you please use following code example. There is no need to create FileStream to save the document to disk.
Hope this helps you. Please let us know if you have any more queries.
unfortunately I need to use FileStream.
Aspose does not support path which is longer than 260 characters (Windows limitation) thus I am using AlphaFS component (which returns FileStream) and does not have limitation of 260 characters.
Of course, if you extend Aspose components I’ll switch back to “easier” approach to open and save documents :-).
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.