Error: "The requested resource is in use"


#1

Hi,

I am having trouble viewing a generated document soon after it had been generated by Aspose.Word. I get the following error:

The requested resource is in use.
at SHDocVw.IWebBrowser2.Navigate(String URL, Object& Flags, Object& TargetFrameName, Object& PostData, Object& Headers)
at AxSHDocVw.AxWebBrowser.Navigate(String uRL, Object& flags, Object& targetFrameName, Object& postData, Object& headers)
at PrintManager.frmView.NavigateFirst()

I am using AxWebbrowser control to navigate to this new page. I have this code at the end of the document generating code:

FileStream fs=null;
fs = new FileStream(oTemplate.ToString(), FileMode.Open, FileAccess.Read);
oDoc = new Document(fs);
if(oDoc.ProtectionType != ProtectionType.NoProtection)
oDoc.Unprotect();

FillData();

oDoc.Protect(ProtectionType.AllowOnlyFormFields);
oDoc.Save(oName.ToString(), SaveFormat.FormatDocument);
oDoc=null;

if(oDoc!=null) oDoc=null;
if(fs!=null) fs.Close(); // closes template file

And here's the NavigateFirst() method I am using:

public void NavigateFirst()
{
if(!navigated && dvDocs.Count > 0 && this.InputFinished)
{
try
{
wbDocs.Navigate(sDir + dvDocs[0]["GFileName"], ref oMissing, ref oMissing, ref oMissing, ref oMissing);
// navigate to first document, after atleast one is generated
this.navigated = true;
}
catch()
{
}
}
}

Is there a way to make sure the generated document is closed completely using Aspose.Word? How come there isn't a Document.Close() method?

Thanks for your help.

piddy
ORTICON


#2

Hi,

Thank you, we’re looking into this issue, will reply you soon.


#3

Document does not have Close() because it never keeps any resources open.

If you open a document from a file, it creates a stream, reads and closes it. If you save a document to a stream, it creates, writes and closes.

In your case you just pass a stream to Aspose.Word and close it yourself so Aspose.Word has absolutely nothing to do. It just writes to the stream.

I don’t think the issue is caused by Aspose.Word in this case.

Just in case, try using the latest version of Aspose.Word where we switched away from using Win32 structured storage interface and work with the file directly.