• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Sharepoint Saturday India Online best practice for developing share point solution
 

Sharepoint Saturday India Online best practice for developing share point solution

on

  • 2,098 views

 

Statistics

Views

Total Views
2,098
Views on SlideShare
718
Embed Views
1,380

Actions

Likes
0
Downloads
8
Comments
0

2 Embeds 1,380

http://www.shakirmajeed.com 1379
http://www.shakirmajeed.com. 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Hello every one, good after noon every one, Welcome to SharePoint Saturday India Online and to my session. Let me assure you the next hour will be quite exciting for us.
  • I am participating in this event from across the border. I am speaking from Karachi, Pakistan
  • An SPWeb or SPSite object can occupy a lot of memory. Avoid constructing objects of these types simply to get a reference to a parent object. Instead, to get a reference to a web application, use the static SPWebApplication.Lookup(Uri) method, and pass it a Uri object that is created with the URI of the web application. You can then get a reference to the farm by using the Farm property of the web application object. (You can get a reference to a remote farm by using the static Open(String) method.) The ContentDatabases property of the web application object contains a collection of the content databases in the web application. You can get a reference to a particular content database through this property if you know its index in the collection. For more information, see the reference topic for the SPContentDatabaseCollection class.
  • Each instance of SPSite and SPWeb contains a reference to an SPRequest object that, in turn, contains a reference to an unmanaged COM object that handles communications with the database server. SharePoint Foundation monitors the number of SPRequest objects that exist in each specific thread and in parallel threads, and adds useful entries to the logs.Whenever the number of SPRequest objects exceeds threshold (Default is 8), an entry appears in the ULS logs:
  • Caching is a good way to improve system performance. However, you must weigh the benefits of caching against the need for thread safety, because some SharePoint objects are not thread safe and caching causes them to perform in unexpected ways.Caching SharePoint Objects That Are Not Thread SafeYou might try to increase performance and memory usage by caching SPListItemCollection objects that are returned from queries. In general, this is a good practice; however, the SPListItemCollection object contains an embedded SPWeb object that is not thread safe and should not be cached.
  • The use of the cache in the preceding example is functionally correct; however, because the ASP.NET cache object is thread safe, it introduces potential performance problems. (For more information about ASP.NET caching, see the Cache class.) If the query in the preceding example takes 10 seconds to complete, many users could try to access that page simultaneously during that amount of time. In this case, all of the users would run the same query, which would attempt to update the same cache object. If that same query runs 10, 50, or 100 times, with multiple threads trying to update the same object at the same time—especially on multiprocess, hyperthreaded computers—performance problems would become especially severe.
  • Avoid creating and destroying objects unnecessarily in code, as this may require that extra queries be made against the database and may even involve code that is incorrect. Tasks list must be instantiated each time the indexer is used to set properties and the method for updating is called. This is not a recommended practice.Tasks list object only once and assigns it to the myList variable in order to set properties and call the method.
  • Target farm level solutions to the specific web application instead of deploying to all web applications unless you are deploying new feature to all the applications in the farm. This way custom feature for the specific web application won’t available on site collection features page or site features page on all the web applications in the farm.Try to deploy all the resource files (CSS, JPG) from within the Solution (Applicable to Sandboxed solution as well)
  • I wont go into the details of the sandboxed solution here, but these are the general rule of thumbPlan 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
  • Using the GUID is preferable because it is unique, permanent, and requires only a single database lookup. The display name indexer retrieves the names of all the lists in the site and then does a string comparison with them. If you have a list URL instead of a GUID, you can use the GetList method in SPWeb to look up the list's GUID in the content database before retrieving the list.
  • When you delete multiple versions of a list item, use the DeleteByID() method; do not use the Delete() method. You will experience performance problems if you delete each SPListItemVersion object from an SPListItemVersionCollection object. The recommended practice is to create an array that contains the ID properties of each version and then delete each version by using the SPFileVersionCollection.DeleteByID method.
  • Do not instantiate an SPWeb, SPSite, SPList, or SPListItem object within an event receiver. Event receivers that instantiate these objects instead of using the instances passed via the event properties can cause the following issues: Significant additional roundtrips to the database (one write operation can result in up to five additional roundtrips in each event receiver). Calls to the Update method on these instances can cause subsequent Update calls in other registered event receivers to fail.
  • Make sure solutions have proper feature name and description. Feature name and description would be visible on the site collection and site features page.Make sure solutions have proper consistent naming conventionDeployment discipline – During the deployment and retraction process while updating or upgrading custom solutions, please use the correct older version of WSPs to retract the solution before deploying or upgrading the custom code with newer version of WSPs. This would ensure activating or deactivating features reference correct version of WSPs.

Sharepoint Saturday India Online best practice for developing share point solution Sharepoint Saturday India Online best practice for developing share point solution Presentation Transcript

  • MySelf 5 year of SharePoint Blogger, Speaker, Hobbyist photographer Technical Lead @ Kalsoft
  • Karachi, Pakistan
  • #Best Practice Quotes“We cannot control the winds, but we can adjust thesails.” Anonymous“Its not necessarily the amount of time you spend atpractice that counts; its what you put into the practice.” Eric Lindros“My secret is practice” David Beckham
  • Best Practice for DevelopingSharePoint Solutions
  • Content to Cover
  • SharePoint Solutions General Consideration  Avoid unnecessary construction of Objects  Disposing objects  Object Caching  Optimizing code performance
  • Avoid unnecessaryconstructionofSPWeb/SPSite Objects SPWeb  SPSite SPWebApplication webApplication = SPWebApplication.Lookup(new Uri(System.String); SPFarm farm = webApplication.Farm; SPContentDatabase content = webApplication.ContentDatabases[S System.Int32];
  • Disposing objects
  • 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
  • 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
  • Disposing objects (Cont..) Rule of thumb Never dispose SPContext, SPContext.Site, SPContext.Current. Site, SPContext.Web, and SPContext.Current.Web.
  • 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()) { // }}
  • Disposing objects (Cont..)  SPSite siteCollection = siteCollections.Add(URL, "DOMAINUser", EMAIL);  using (SPSite siteCollection = siteCollections.Add(URL, "DOMAINUser", EMAIL) { }
  • Disposing objects (Cont..)  SPWeb web = siteCollection.AllWebs.Add(URL);  using (SPWeb web = siteCollection.AllWebs.Add(URL) { }
  • Disposing objects (Cont..)Download the SPDispose Check toolhttp://code.msdn.microsoft.com/SPDisposeCheck
  • Object Caching  public void CacheData() { SPListItemCollection oListItems; oListItems = (SPListItemCollection)Cache["ListItemCacheName"]; if(oListItems == null) { oListItems = DoQueryToReturnItems(); Cache.Add("ListItemCacheName", oListItems, ..); } }
  • 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, ..); } } }
  • Optimizing codeperformance  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();
  • 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)
  • 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
  • Working With Large Lists
  • Working With Large Lists  SPWeb.Lists[strDisplayName]  SPWeb.Lists[GUID]  SPWeb.GetList(strURL)
  • Working With Large Lists(Cont..)  SPList.Items  SPList.Items.Add  SPList.Items.GetItemById  SPList.GetItems(SPQuery query)  SPList.AddItem  SPList.GetItemById(int id, string field1, params string[] fields)
  • Working With Large Lists(Cont..)  SPList.Items.Count  SPList.Items[System.Guid]  SPList.Items[System.Int32]  SPList.Items.GetItemById(Syste m.Int32)  SPList.ItemCount  SPList.GetItemByUniqueId(Syste m.Guid)  SPList.GetItemById(System.Int32)
  • Working With Large Lists(Cont..)  SPFolder.Files.Count  SPFolder.Files[System.String]  SPFolder.ItemCount  SPFolder.ParentWeb.GetFile(SPU rlUtility.CombineUrl(SPFolder.Url, System.String)
  • Working With Large Lists(Cont..) Deleting Versions  SPListItemVersion.GetVersionFr omID(System.Int32). Delete();  SPFileVersionCollection. DeleteByID(System.Int32);
  • Event Receivers
  • 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.
  • Event Receivers (Cont..)  Instantiate an SPWeb, SPSite, SPList, or SPListItem  Update method  properties.OpenWeb()  properties.ListItem
  • 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,SPCo ntext.Current.Web
  • 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
  • Thank You