Dispose Sharepoint object SPSite - InfoPath Dev
in

InfoPath Dev

Dispose Sharepoint object SPSite

Last post 03-24-2009 07:57 AM by CraigW. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 03-23-2009 01:59 PM

    Dispose Sharepoint object SPSite

    How can I dispose sharepoint objects using SPSite through VSTA code using C#?

  • 03-23-2009 02:14 PM In reply to

    Re: Dispose Sharepoint object SPSite

    Hi rishibajaj,

    Do you mean an SPSite object itself?  If so, just call mySPSiteObj.Dispose();

    It is preferred though that you use a using() statement:

    using (SPSite mySPSiteObj = new SPSite(http://myserver/mysite))
    {
    // your code here
    }

    The SPSite object is then disposed for you.

    Craig

  • 03-23-2009 02:22 PM In reply to

    Re: Dispose Sharepoint object SPSite

    How can I get access to "mySPSiteObj" object?

    --------------

    I have written this code and every time I execute this code I am getting this exception. I am running this code on Win XP machine where there is no MOSS installed. I am getting this exception-

    ---------------

    {System.TypeInitializationException: The type initializer for 'Microsoft.SharePoint.CoreResource' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.SharePoint.intl, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.
    File name: 'Microsoft.SharePoint.intl, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
       at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
       at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
       at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
       at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
       at System.Reflection.Assembly.Load(String assemblyString)
       at Microsoft.SharePoint.CoreResource..cctor()

    --- End of inner exception stack trace ---
       at Microsoft.SharePoint.CoreResource.GetString(ResourceGroup rg, String name, Object[] values)
       at Microsoft.SharePoint.SPResource.GetString(String name, Object[] values)
       at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)
       at Microsoft.SharePoint.SPSite..ctor(String requestUrl)
       at EntityManagement03202009.FormCode.CTRL242_4_Clicked(Object sender, ClickedEventArgs e)}

    ------------------

    my code is here :-

    try

    {        using (SPSite site = new SPSite("http://localhost/"))

            {

            }

    }

    catch (Exception ex)

    {

    }

    finally

    {

    site.Dispose();

    }

     

     

     

  • 03-24-2009 06:32 AM In reply to

    Re: Dispose Sharepoint object SPSite

    Are you developing on a SharePoint server?

  • 03-24-2009 06:53 AM In reply to

    Re: Dispose Sharepoint object SPSite

    No, I am developing on Win XP Machine which does not have sharepoint server.

  • 03-24-2009 07:57 AM In reply to

    Re: Dispose Sharepoint object SPSite

    I thought as much. Unfortunately, you will be unable to write code that accesses the SharePoint API unless you are on a SharePoint server.

    The Url property of the SPSite constructor must refer to a site that is in the Server Farm that the code is running on.  It cannot be used to connect to a remote farm.  To do that, use web services.

    Craig

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