in

InfoPath Dev

Security exception - infopath view.export, system.io

Last post 06-28-2008 11:59 AM by morten. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 06-27-2008 02:12 PM

    • morten
    • Not Ranked
    • Joined on 06-27-2008
    • Posts 2

    Security exception - infopath view.export, system.io

    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

  • 06-27-2008 03:45 PM In reply to

    • Albert
    • Top 150 Contributor
    • Joined on 04-03-2008
    • The Netherlands
    • Posts 32

    Re: Security exception - infopath view.export, system.io

    I think this is an InfoPath instead of .NET security issue. If you look at the View.Export method on msdn(http://msdn.microsoft.com/en-us/library/microsoft.office.infopath.view.export(VS.80).aspx) you'll find the following:

    This member can be accessed only by forms opened from a form template that as been configured to run with full trust using the Security and Trust category of the Form Options dialog box. This member requires full trust for the immediate caller and cannot be used by partially trusted code. For more information, see "Using Libraries from Partially Trusted Code" on MSDN.  

    This means that your form should be fullytrusted to export the view to mht (or pdf/xps). There is a good article on msdn called 'Understanding fully trusted forms': http://msdn.microsoft.com/en-us/library/aa662309(office.11).aspx. Its a lot to read, but i will summarize it: if you want a fully trusted you have 2 options:

    1. digitally sign the form
    2. install the form on the local machine (can you use regform.exe to build an installation script)

    I know this a pain, but its a fact.

    As an alternative you might want to check out the MailEnvelope object (http://msdn.microsoft.com/en-us/library/microsoft.office.infopath.window.mailenvelope(VS.80).aspx). For an example (jscript) you can look at the following post: http://www.infopathdev.com/forums/p/5780/27701.aspx#27701.

    Good luck,

    Albert

  • 06-28-2008 11:59 AM In reply to

    • morten
    • Not Ranked
    • Joined on 06-27-2008
    • Posts 2

    Re: Security exception - infopath view.export, system.io

    Hi Albert, thank you so much for your quick reply. It is highly appreciated.

    The mailenvelope object will do the job for me :)

     

    Best regards,
    Morten 

Page 1 of 1 (3 items)
Copyright © 2003-2007 Qdabra Software. All rights reserved.
View our Terms of Use.