locked
SPSite-Constructor throws TypeInitializationException RRS feed

  • Question

  • Hello everybody,

    i have an InfoPath-Form with some C#-Code.

    In the line

    using (SPSite site = new SPSite("URL"))

    i get a TypeInitializationException. URL is correct.

    Any ideas how i can fix that?

    Wednesday, September 5, 2012 8:53 AM

All replies

  • Hi,

    Are you using an InfoPath Form Services form? Is it open Inside your browser?

    The SPSite only works on the SharePoint Server context.


    Visit my blog : http://rmatayron.blogspot.com/

    Wednesday, September 5, 2012 11:40 AM
  • No, it does not open inside the browser. How can I force it to open in browser?

    The TypeInitializationException is fixed, i had to add the Microsoft.Sharepoint.intl-Assembly, but now I get a FileNotFoundException on the same code line....

    Thursday, September 6, 2012 8:24 AM
  • Hi,

    The "Microsoft.SharePoint" assembly only works on the SharePoint server, that's why you got the error...

    To open your form Inside the browser:

    • Go into your form options Inside the "Compatibility" tab and check that "Browser form" is selected,
    • Inside your form Library in SharePoint, go to "Advanced settings" and check "Open in browser" (if you use SP 2010).

    Hope htis helps.


    Visit my blog : http://rmatayron.blogspot.com/

    Thursday, September 6, 2012 8:28 AM
  • I get several errors in my form when I change it to open in Browser, some things are not supported. That´s no option.

    The thing I want to do with the SPSite-code is to upload a File-Attachement in my Form to annother Sharepoint-Documentlibrary. Is there some other possibility to do that?

    Thursday, September 6, 2012 8:40 AM
  • Hi,

    You can do it using SharePoint Web Services.

    IF your form is opening on office client on your PC, I cannot use the SharePoint model object but you must use web services of SharePoint.

    For example, you can do this kind of code:

    http://farhanfaiz.wordpress.com/2009/09/16/sharepoint-upload-file-using-web-service/

    http://www.oriolardevol.com/Article/Details/3

    Hope this helps.


    Visit my blog : http://rmatayron.blogspot.com/

    Thursday, September 6, 2012 9:39 AM
  • Hi,

    Is this working for you?


    Visit my blog : http://rmatayron.blogspot.com/

    Monday, September 10, 2012 3:05 PM