Runtime Security Exception occurs for the following code:
Dim doc As Aspose.Words.Document
doc = New Document(mydir + "mydoc.docx") <<<<<<<<
Runtime Security Exception:
Request for the permission of type ‘System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.
Thank you for additional information. As an option, you can read your document into stream and then open document from stream. You can use code like the following:
// Open document into stream.
Stream docStream = File.OpenRead(@"C:\temp\in.doc");
// Create Document object from stream.
Document doc = new Document(docStream);
If this will not help, try specifying the following options upon reading the document into stream.
// The specified file can be opened in MS Word in moment of opening it using Aspose.Words.
string fileName = @"C:\Temp\in.doc";
// Open docuemnt
FileStream docStream = new System.IO.FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
// Create Aspose.Words Document from stream
Document doc = new Document(docStream);
// Close stream
docStream.Close();
// Do somethisng with document
// Save document
doc.Save(@"C:\Temp\out.doc");
Hi Alexy (or anyone else on Aspose tech staff who may know),
I am now receiving the same System.Security.Permissions.FileIOPermission exception on the document.Save() portion of the above code you sent (code as I have it below):
Thanks for your request. Could you please make sure that you have write permissions to this folder. For instance, try creating a simple text document from code:
using (StreamWriter txtFileWriter = File.CreateText(@"C:\Temp\test.txt"))
{
txtFileWriter.Write("Hello World!!!");
}
If this code will also throw an exception, then there are some problems with permissions on your side.
Have you tried moving the Aspose.Words.dll to the same server as the application and seeing if the exception disappears?
Regarding your request for best mail merge practices, you can find full details on mail merge in the documentation here. Which mail merge methods were you using that become “obselete”?
And also about the fact you have a library located on another server. Is it possible to move it closer to your application? Or add to the GAC on the machine where you run the project.
Unfortunately this did not work either. I still believe that it is something to do with Code Access Security (CAS), but can’t figure out what exactly to do to modify it. I just gave up and made IIS recognize it as a Classic .NET app pool.
It’s great that it’s working now. Did you ever try moving the DLL to the same location and seeing if that solved the issue? This could provide further insight into where the real issue was coming from.
Thanks,
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.