'Saving Aspose.Slides.Presentation prevents file from being opened
I am attempting to modify a Presentation file with Aspose.Slides.
var fileMemoryStream = new MemoryStream();
await fileMemoryStream.WriteAsync(file.FileData, 0, file.FileData.Length);
Presentation pres = new Presentation(fileMemoryStream);
IDocumentProperties pptProperties = pres.DocumentProperties;
pptProperties.Title = "test";
pres.Save(fileMemoryStream, Aspose.Slides.Export.SaveFormat.Pptx);
fileMemoryStream.Position = 0;
fileData = fileMemoryStream.ToArray();
var contentType = fileProperties.MimeTypes.ContainsKey(file.Extension) ? fileProperties.MimeTypes[file.Extension]: "application"+file.Extension.Replace(".", "/");
var fileConvert = File(fileData, contentType, exemplarFile.DownloadName + file.Extension);
Ff I comment out the pres.Save line, the file works. If I don't, it won't open and I'm left with the message below.
"Powerpoint found a problem with content in path.pptx. Powerpoint can attempt to repair the presentation."
If I comment out pptProperties.Title = "test";, it does not work. setting the fileMemoryStream to zero at the beginning does not work. I must be missing a step in the Aspose process, or the memorystream process. Any ideas?
Note: the file being tested is a pptx file and the Mimetype is correct
application/vnd.openxmlformats-officedocument.presentationml.presentation
Solution 1:[1]
I'm not sure what was happening, but saving the pres to a new MemoryStream instead of the current one worked.
If anyone has an idea as to why this is feel free to post, but this is what solved this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | alrightgame |