We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Opening a document template as aspose.Document causes file to be locked

I am developing a web app that accesses document templates on the server, creates aspose.document objects, performs a mail merge, and then prints them out.

The problem I have been having is that the file seems to get locked occasionally. This problem is rare, and is very hard to reproduce.

The thing that is puzzling, is that I open the file as read access and read sharing, into a file stream, read the file stream into a byte array, dispose of the file stream, and then create a memory stream from the byte array. The aspose document is opened from the memory stream. See Code below:

private MemoryStream CreateMemoryStream(string documentTemplatePath){

byte[] b;

using (FileStream fs = new FileStream(documentTemplatePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
b = new byte[fs.Length];
fs.Read(b, 0, b.Length);
}

return new MemoryStream(b);} // the aspose document is created from this memory stream.

Although it is a web app the usage is low, the documents being opened can not be opened for editing and the duration of the locking is significantly longer than the the duration of the using statement above (not that this should lock the file because of the file access and file share options).

Do you know of any way, or situation that I may have overlooked that would result in an aspose.document locking the file?

Thanks

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. The document is not locked during processing using Aspose.Words. Aspose.Words reads document to memory. So this could occur if few streams read file simultaneously. You can try to check whether file can be read and then read the file.

Best regards.