Agusto Xaverius P Sipahutar

Job:Making some bugs and patch
Moss/Wss,C#,Sql Server,WWF,K2.BlackPearl
Motto : Keep Study and study
See also: Other Geeks@INDC

News




MCP Logo
MCTS Logo

MCP ID# 3542391

My Curiculum Vitae


Agusto Xaverius P S's Facebook profile

Other Article

My Community

My Article/Share Knowledge

Others Moss/Wss Site

My Other Website/Blogs

My Share (Ebook,etc)

Using Disposable on MOSS/WSS 3.0

Best practice di microsoft site menuliskan bahwa sebaiknya melakukan disposable open koneksi ke sharepoint.

2 (Dua) class dari Sharepoint object model untuk membuka koneksi ke Sharepoint yaitu SPSite Class dan SPWeb Class.

Ada beberapa teknik yang bisa dilakukan untuk melakukan disposeable yaitu :

Contoh penggunaan using clause

String str;

using(SPSite oSPsite = new SPSite("http://server"))
{
  using(SPWeb oSPWeb = oSPSite.OpenWeb())
   {
       str = oSPWeb.Title;
       str = oSPWeb.Url;
   }

 

Contoh penggunaan try/catch/finally Blocks

String str;
SPSite oSPSite = null;
SPWeb oSPWeb = null;

try
{
   oSPSite = new SPSite("http://server");
   oSPWeb = oSPSite.OpenWeb(..);

   str = oSPWeb.Title;
}
catch(Exception e)
{
}
finally
{
   if (oSPWeb != null)
     oSPWeb.Dispose();

   if (oSPSite != null)
      oSPSite.Dispose();
}

Catatan :

Bila melakukan koneksi ke Sharepoint menggunakan SPContext.Current.Site.RootWeb untuk hal ini tidak perlu dilakukan dispose karena akan terjadi error pada site nya bila dilakukan dispose.

 

Referensi : http://msdn.microsoft.com/en-us/library/aa973248.aspx

Share this post: | | | |
Posted: Dec 01 2008, 03:39 PM by agusto | with 1 comment(s)
Filed under:

Comments

Agusto Xaverius P Sipahutar said:

Saya pernah membahas suatu tips on trik untuk WSS/SharePoint custom code salah satunya adalah mengenai

# February 4, 2009 1:26 AM