Simple file open and save problem


#1

My code is something like this:

FileCopy(m_setup.template, m_filename)

asp = New Aspose.PowerPoint.Presentation(m_filename)

'Add new pages

'Replace text on all pages

asp.Write(m_filename)

But sometimes I get an exception on the write statement for the file already being used by another process.

I’m not threading, so who could have it open?


#2

You can’t save presentation to the same file.


#3

If I have multiple threads (I don’t yet but it’s somewhere in my future) that want to modify the same file, but with different data, how do I do it?

Should I copy the template to a temporary file, make the changes, save under the permanent name, then delete the temp file?

Or can I have multiple threads modifying the same template file as long as they save to different names?


#4

Yes, you should use temporary file.

It’s possible to read the same file from different threads but you need to open it as read-only stream and use another constructor for Presentation class.