Month: April 2012

CAML.NET

Posted on

Nothing new here, just a link I want to have to find it easily again later, I will add this to my sharepoint arsenal, I definitely think its pretty awesome and needed.

http://www.sharepointnutsandbolts.com/2011/02/camlnet-intellisense-now-with-added.html

Advertisements

Not good coding practice found in a book by Arpan Shah. Sharepoint 2010 Development with Visual Studio 2010

Posted on

There is not a big deal in this error from the author, but its interesting that somebody from Microsoft itself makes this mistake after its revealed in the disposal best practices.

Chapter 3:  Introduction o the Sharepoint Object Model.

Page 185.

He used:

using(SPWeb rootWeb = site.RootWeb)

{

}

This is not a good coding practice because the RootWeb does not need disposal, I had SPRequest errors in my log in the past because of this exact same line.  SO AVOID IT.

this is documented here:

http://sharepoint.stackexchange.com/questions/33264/spdispose-false-positive

Posted on

wow

Luis Valencia - Sharepoint Architect

There is not a big deal in this error from the author, but its interesting that somebody from Microsoft itself makes this mistake after its revealed in the disposal best practices.

Chapter 3:  Introduction o the Sharepoint Object Model.

Page 185.

He used:

using(SPWeb rootWeb = site.RootWeb)

{

}

This is not a good coding practice because the RootWeb does not need disposal, I had SPRequest errors in my log in the past because of this exact same line.  SO AVOID IT.

this is documented here:

http://sharepoint.stackexchange.com/questions/33264/spdispose-false-positive

View original post

Not good coding practice found in a book by Arpan Shah. Sharepoint 2010 Development with Visual Studio 2010

Posted on

There is not a big deal in this error from the author, but its interesting that somebody from Microsoft itself makes this mistake after its revealed in the disposal best practices.

Chapter 3:  Introduction o the Sharepoint Object Model.

Page 185.

He used:

using(SPWeb rootWeb = site.RootWeb)

{

}

This is not a good coding practice because the RootWeb does not need disposal, I had SPRequest errors in my log in the past because of this exact same line.  SO AVOID IT.

this is documented here:

http://sharepoint.stackexchange.com/questions/33264/spdispose-false-positive

SPSite and SPWeb instantiation vs SPContext.SPSite and SPContext.SPWeb

Posted on

Most often that I wish I see really bad practices about this specific thing.
Most developers just open visual studio and the first thing they do is just

SPSite site= new SPSite(spcontext.current.site.url)

Others jut use SpContext.Current.Site.Url inmediately.

Well, I am going to explain some of reasons when you should use a new SPSite or SPWeb object or when you should use the SPContect.Current.Site and .Web.

The following list might grow as I start receiving comments via mail, but this is heavily explained in some other blogs out there:

1. The fact of doing a new SPSite or new SPWeb, it uses lots of SPRequest objects, creation of these 2 objects is highly resource intensive and very expensive in terms of CPU time.
2. No because you can, doesnt mean you should, This sentence is actually from Randy Williams, and with this permission I use it here, DO NOT start coding with a new object first, first think and then do.
3. SPContext should be used when you dont need to run some code with elevated privileges, SPContext uses the current user permissions, so be aware of that.
For example if you create an application page which reads a list, but that list is read only for all users, then you need RunWithElevatedPrivileges and then you need to instantiate the SPSite or SPWeb object.
4. When to instantiate a new SPSite or SPWeb.

  • When the running code is not inside a sharepoint context (eg: timer job, Client application)
  • When the running code needs to access resources that users normally wont have access to (eg: list data)
  • When you need to access data from another Site collection/site than the current

5. Another fact:

  • This is true in other areas of development, like SqlConnection.
  • Leave the objects opened only for the operations you need, the faster you close it the more resources you free.