Permissions error on displaying document (AspDoc.Save)

Here is the code in my program. When it gets to the AspDoc.Save(“out.doc”) I get the error below. I also tried other AspDoc.Save types shown below. ANY IDEAS??

Dim AspdocStream As MemoryStream = New MemoryStream(CType(objZLib.m_arbytDeCompressionBuffer, Byte()), 0, CType(viewReader("Length"), Integer))
Dim AspDoc As Document = New Document(AspdocStream)
AspDoc.Unprotect()
AspDoc.Save("out.doc")
'AspDoc.Save("Out.Doc", SaveFormat.Doc, SaveType.OpenInWord, Response)
'AspDoc.Save("Out.Doc", SaveFormat.Doc, SaveType.OpenInApplication, Response)
'AspDoc.Save("Out.Doc", SaveFormat.Doc, SaveType.OpenInBrowser, Response)

Error:

ex = {"Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."}

When I did SaveType.OpenInBrowser I got this error instead:

ex = {"Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."}

Hi

Thanks for your inquiry. From the error message you provided, I can suppose that the problem occurs because there is something wrong with permissions settings on your side. Please try also saving the document to stream as shown below:

MemoryStream docStream = new MemoryStream();
doc.Save(docStream, SaveFormat.Doc);

If such code will not throw an exception, you can be sure that the problem is on your side.
Best regards.

I changed it to below and nothing happened. I didn’t get an error this time, but the document didn’t display either. Nothing at all happened.

Dim AspdocStream As MemoryStream = New MemoryStream(CType(objZLib.m_arbytDeCompressionBuffer, Byte()), 0, CType(viewReader("Length"), Integer))
Dim AspDoc As Document = New Document(AspdocStream)
AspDoc.Unprotect()
AspDoc.Save(AspdocStream, SaveFormat.Doc)

Hi

Thanks for your request. Actually, this code just save the document into a stream, so you should not see nothing. I suggested this code just for testing. As you can see Aspose.Words does not throw an exception upon saving, so the problem is somewhere on your side.
The Save(“out.doc”, SaveFormat.Doc, SaveType.OpenInWord, Response) method works like the following code.

Aspose.Words.Document doc = new Aspose.Words.Document();
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
builder.Write("Hello world!!!");
MemoryStream stream = new MemoryStream();
doc.Save(stream, SaveFormat.Doc);
Response.Clear();
// Specify the document type.
Response.ContentType = "application/msword";
// Other options:
// Response.ContentType = "text/plain"
// Response.ContentType = "text/html"
// Specify how the document is sent to the browser.
// Response.AddHeader("content-disposition","attachment; filename=MyDocument.doc");
// Another option could be:
Response.AddHeader("content-disposition", "inline; filename=MyDocument.doc");
// Get data bytes from the stream and send it to the response.
byte[] bytes = stream.GetBuffer();
Response.BinaryWrite(bytes);
Response.End();

You can try using this code for testing, if the exception occurs in the highlighted part, then the problem is not related to Aspose.Words but to your environment configuration.
Best regards.