Hi all,
I would like infopath to export a single html file (.MHT) using code-behind (c#). The purpose of this, is to send this file as an e-mail attachment to recipients from a repeating table in the form by code.
On my form, I have a button with the following code:
thisXDocument.View.Export(@"c:\temp\myFile.mht", "MHT");
In .net configuration 1.1 I did the following:
I strongnamed the dll, and in the runtime security policy I made a new codegroup. In that group, in the tab "membership condition", the condition type is set to "Strong Name". (where I imported the dll from my project.)
The permission set in the group is "FullTrust".
By doing this, I was able to connect to a sql database, and to get directory info by using the System.IO.DirectoryInfo object. But I could not export a file to the diskdrive by using the view.export method.
I got this exception message:
"System.Security.SecurityException: Security error. at Microsoft.Office.Interop.InfoPath.SemiTrust.ViewObjectWrapper.Export(String bstrURL, String bstrFormat) at " ... (and the reference to the line in my code)
I also tried to make a temporary certificate and setting the trust level to full in infopath before publishing the form. In that case, the code run sucsessfully. I am developing this remotely, and I can't use the sharepoint object model, because of an exception regarding a wrong version on that site. (I don't remember the exception message)
I have tried to turn off security by using both of these commands: "caspol -s off" and "caspol -e off". Still, it throws the exception.
Can anyone explain to me what causes the security exception? I get this exception when running the form locally on my computer and when I open it from sharepoint (local server)
Best regards,
Morten