Monday, March 14, 2011

SP2010 Few code changes for 2007 code

Scenario:
While a lot of my clients are asking for migration to SP2010 from MOSS2007. One important task is to upgrade the code / solutions. So I though of start documenting few code/design change to utilize new APIs.

Design Changes:
1. ContentIterator class for processing large lists ( 5000+ items )
2. Remote Blob storage for very large files ( 50MB+ )
3. Sandbox solutions ( Webparts / Infopath wide code-behind etc. )
4. Client Object Model
5. Powershell based deployments

Code related Changes:


// 1. Easy to validate column exist or not
if(list.Fields.ContainsFieldWithStaticName(columnName))
{
// do something
}

// 2. Easy to get field by internal name
SPField field = list.Fields.GetFieldByInternalName(columnName)

// 3. Code return null in case list is not present
SPList list = web.Lists.TryGetList(listTitle)

// 4. Working with folders is better now
if(folders.TryGetFolder(folderUrl, out folder))
{
// do something
}

// 5. Check if the list has folders other than the root folder
if (!SPFolderHierarchy.ListHasFolders(list))
return;

// 6. Cache support - brand new in SP2010
SPCache.Cache.Put(DataCache, new SPCachedObject("TestKey", new TestCustomClass(), null, new TimeSpan(1, 0, 0)));

SPCache.Cache.Get(DataCache, "TestKey");
SPCache.Cache.Delete(DataCache, "TestKey");

// 7. Client Object Model based utilities
var encodedUrl = SP.Utilities.HttpUtility.ecmaScriptStringLiteralEncode(viewServ);

SP.Utilities.HttpUtility.appendSourceAndNavigateTo(this.newUrl);

// 8. Client Object Model based utlities - 2
this.imageUrl = SP.Utilities.Utility.getImageUrl('sandeepPhoto.jpg');
this.pageUrl = SP.Utilities.Utility.getLayoutsPageUrl('myHome.aspx')




Article:
I will update this post on regular basis with new findings.

0 comments: