Sharepoint Saturday India Online best practice for developing share point solution
-
Upload
shakir-khan -
Category
Technology
-
view
2.109 -
download
3
Transcript of Sharepoint Saturday India Online best practice for developing share point solution
![Page 1: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/1.jpg)
BEST PRACTICE FOR DEVELOPING SHAREPOINT SOLUTIONS
Shakir Majeed Khanwww.shakirmajeed.com@[email protected]
![Page 2: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/2.jpg)
MySelf5 year of SharePoint
Blogger, Speaker, Hobbyist photographer
Technical Lead @ Kalsoft
![Page 3: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/3.jpg)
Karachi, Pakistan
![Page 4: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/4.jpg)
#Best Practice Quotes“We cannot control the winds, but we can adjust the sails.” Anonymous
“It's not necessarily the amount of time you spend at practice that counts; it's what you put into the practice.” Eric Lindros
“My secret is practice” David Beckham
![Page 5: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/5.jpg)
Best Practice for Developing SharePoint Solutions
![Page 6: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/6.jpg)
Content to Cover
SharePoint Solution
Farm Solutions
Working With Large List
General Consideration
Sand boxed Solution
Event Receivers Timer Jobs
![Page 7: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/7.jpg)
SharePoint Solutions
General ConsiderationAvoid unnecessary construction
of ObjectsDisposing objectsObject CachingOptimizing code performance
![Page 8: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/8.jpg)
Avoid unnecessary construction of SPWeb/SPSite ObjectsSPWeb
SPSite
SPWebApplication webApplication = SPWebApplication.Lookup(new Uri(System.String);
SPFarm farm = webApplication.Farm;
SPContentDatabase content = webApplication.ContentDatabases[SSystem.Int32];
![Page 9: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/9.jpg)
Disposing objects
![Page 10: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/10.jpg)
Disposing objects (Cont..) Symptoms
Application pool recycle frequently, especially under heavy loads
System perform poorly, especially under heavy loads
System crash or do users experience unexpected errors such as timeouts or page-not-available errors, especially under heavy loads
![Page 11: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/11.jpg)
Disposing objects (Cont..) Why Dispose?
SPSite class and SPWeb class objects, are created as managed objects
Each instance of SPSite and SPWeb contains a reference to an SPRequest object that, in turn, contains a reference to an unmanaged COM object
![Page 12: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/12.jpg)
Disposing objects (Cont..) Rule of thumb
Never dispose SPContext, SPContext.Site, SPContext.Current.Site, SPContext.Web, and SPContext.Current.Web.
![Page 13: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/13.jpg)
Disposing objects (Cont..)
using (SPWeb web = new SPSite(SPContext.Current.Web.Url).OpenWeb()) { //
}
using (SPSite siteCollection = new SPSite(SPContext.Current.Web.Url)) { using (SPWeb web = siteCollection.OpenWeb()) {
//
}}
![Page 14: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/14.jpg)
Disposing objects (Cont..)
SPSite siteCollection = siteCollections.Add(URL, "DOMAIN\\User", EMAIL);
using (SPSite siteCollection = siteCollections.Add(URL, "DOMAIN\\User", EMAIL)
{
}
![Page 15: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/15.jpg)
Disposing objects (Cont..)
SPWeb web = siteCollection.AllWebs.Add(URL);
using (SPWeb web = siteCollection.AllWebs.Add(URL)
{
}
![Page 16: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/16.jpg)
Disposing objects (Cont..)Download the SPDispose Check tool
http://code.msdn.microsoft.com/SPDisposeCheck
![Page 17: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/17.jpg)
Object Cachingpublic void CacheData() { SPListItemCollection
oListItems; oListItems = (SPListItemCollection)Cache["ListItemCacheName"]; if(oListItems == null) { oListItems = DoQueryToReturnItems(); Cache.Add("ListItemCacheName", oListItems, ..); } }
![Page 18: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/18.jpg)
Object Cachingpublic void CacheData() {
DataTable oDataTable; SPListItemCollection oListItems;
lock(_lock) {
oDataTable = (DataTable)Cache["ListItemCacheName"]; if(oDataTable == null) {
oListItems = DoQueryToReturnItems();
oDataTable = oListItems.GetDataTable(); Cache.Add("ListItemCacheName", oDataTable, ..); } } }
![Page 19: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/19.jpg)
Optimizing code performance
SPWeb myWeb = SPContext.Current.Web; myWeb.Lists["Tasks"].Title = "List_Title"; myWeb.Lists["Tasks"].Description = "List_Description"; myWeb.Lists["Tasks"].Update();
SPWeb myWeb = SPContext.Current.Web; SPList myList = myWeb.Lists["Tasks"]; myList.Title="List_Title"; myList.Description="List_Description"; myList.Update();
![Page 20: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/20.jpg)
Farm Solutions
Target farm level solutions to the specific web application instead of deploying to all web applications.
Try to deploy all the resource files (CSS, JPG) from within the Solution (Applicable to Sandboxed solution as well)
![Page 21: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/21.jpg)
Sandboxed Solutions
Plan which servers will run the sandboxed solutions service.
Plan which site collections will be able to run sandboxed solutions.
Design your Sand Boxed solution as per the Site collection quota
![Page 22: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/22.jpg)
Working With Large Lists
![Page 23: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/23.jpg)
Working With Large ListsSPWeb.Lists[strDisplayName]
SPWeb.Lists[GUID]SPWeb.GetList(strURL)
![Page 24: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/24.jpg)
Working With Large Lists (Cont..)
SPList.ItemsSPList.Items.AddSPList.Items.GetItemById
SPList.GetItems(SPQuery query)SPList.AddItemSPList.GetItemById(int id, string
field1, params string[] fields)
![Page 25: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/25.jpg)
Working With Large Lists (Cont..)
SPList.Items.CountSPList.Items[System.Guid]SPList.Items[System.Int32] SPList.Items.GetItemById(Syste
m.Int32)
SPList.ItemCountSPList.GetItemByUniqueId(Syste
m.Guid) SPList.GetItemById(System.Int32)
![Page 26: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/26.jpg)
Working With Large Lists (Cont..)
SPFolder.Files.CountSPFolder.Files[System.String]
SPFolder.ItemCountSPFolder.ParentWeb.GetFile(SPU
rlUtility.CombineUrl(SPFolder.Url, System.String)
![Page 27: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/27.jpg)
Working With Large Lists (Cont..) Deleting Versions
SPListItemVersion.GetVersionFromID(System.Int32). Delete();
SPFileVersionCollection. DeleteByID(System.Int32);
![Page 28: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/28.jpg)
Event Receivers
![Page 29: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/29.jpg)
Event Receivers
Always use Event Receivers to execute the code immediately. Workflows can perform similar function but it will run as a timer job which may delay the code execution.
![Page 30: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/30.jpg)
Event Receivers (Cont..)Instantiate an SPWeb, SPSite,
SPList, or SPListItemUpdate method
properties.OpenWeb()properties.ListItem
![Page 31: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/31.jpg)
Timer Jobs
Always run the timer job in off hours Always perform take out the timer job
when deactivating the respective feature
Don’t use SPContext,SPContext.Current,SPContext.Current.Web
![Page 32: Sharepoint Saturday India Online best practice for developing share point solution](https://reader035.fdocuments.in/reader035/viewer/2022062703/554ebd43b4c905de468b48a8/html5/thumbnails/32.jpg)
General Considerations
Use proper feature name and description.
Use the feature as it require by design. Make sure solutions have proper
consistent naming convention. Use the correct older version of WSPs
to retract the solution before deploying or upgrading the custom code