TypeScript For SharePoint 2013

Saturday, April 20, 2013

SharePoint App and JavaScript CSOM.

Major change in Microsoft SharePoint 2013 development Module  is SharePoint Apps . Previously We have 2 types of solution in SharePoint 2010 1  Farm Solution and  Sandbox Solution. Farm Solution  used full server side SharePoint API and Run SharePoint worker Process. And Sandbox have few limitations  and partially trusted solution which run under the site collection. The biggest change in SharePoint 2013 is App  Solution. Where everything is running outside the SharePoint . App Module is all about HTML 5 , Javascript, Jquery , CSS , Json, JavaScript CSOM. Mainly.  Microsoft greatly enhanced and improved JavaScript CSOM. To meet the Enterprise Development Requirement. SharePoint 2013 Developers need more JavaScript skills to build  large scalable Apps based on JavaScript CSOM. Which required better and highly-productive development tools .Which helps to build robust Apps. So Answer is Typescript,light switch Visual Studio 2012.

The typescript is designed by Microsoft language for Large JavaScript based Application and Module Development .The typescript is a typed superset of JavaScript that compiles to plain JavaScript. And Provide great OOP advantages. You can create
Optional types, classes, and modules to develop large JavaScript programs. Its free and Open Source language which designed by Anders Hejlsberg lead architect of C#. You can extend JavaScript syntax without any changes. Typescript plugin is
Available for Visual Studio 2012 where you can get maximum advantage of working on strong typing and intelligence.  Which make your JavaScript Development Very easy.

Download:  Play : Learn http://www.typescriptlang.org


SharePoint Typescript Definitions
  Type definitions is required for information about Types of variables, parameters, methods, Classes, Modules. Which is by default not available for SharePoint. Might be at some later stage Microsoft Will Provide that OOB. But now thank to the Passionate Typescript Community. MVP Andrey Markeev and  Stas Vyshchepan. Create Open Source  Type Script Definitions  for SharePoint Project on Codeplex . Advantages of SharePoint Type Script Definitions is when you are working on SharePoint 2013 App Module or JavaScript CSOM. By using Typescript with Typescript Definitions for SharePoint you get leverage of OOP, and benefit from strong typing and intelligence.

  1. Client Side Object Model (CSOM) core classes
    • SP namespace (ready)
    • SP.WebParts (ready)
    • SP.Utilities (work in progress) - DateUtility and HttpUtility classes aren't ready yet
    • SP.SOD (ready)
  2. Social object library
    • SP.Sharing (ready)
    • SP.UserProfiles (ready)
    • SP.Social (ready)
  3. SharePoint Client Side Rendering 
    • SPClientTemplates (ready)
  4. Workflows
    • SP.Workflow (ready)
    • SP.WorkflowServices (ready)
  5. SharePoint UI elements:
    • SP.UI.Notify (ready)
    • SP.UI.Status (ready)
    • SP.UI.Menu (ready)
    • SP.UI.ModalDialog (ready)
    • SP.UI.ApplicationPages - some useful stuff here nobody knows about e.g. ClientPeoplePickerWebServiceInterface! (ready)
    • CalloutManager (ready)
    • SP.UI.TileView (planned)
    • SP.UI.Controls (planned)
    • SP.UI.ComboBox (planned)
  6. SharePoint Search
    • Microsoft.SharePoint.Client.Search (ready)
  7. Business Connectivity Services
    • SP.BusinessData (ready)
  8. SharePoint Managed Metadata
    • SP.Taxonomy (ready)
  9. SharePoint Publishing Infrastructure
    • SP.Publishing (planned)

SHAREPOITN 2010 Event Receivers Tip

Monday, April 8, 2013

don't  instantiate  SPWeb,SPSite,SPlist or SPListItem Objects with in event reciver. instantiating these Objects in side the event Receiver can cost you  more roundtrips to the database.

don't code like that

  using (SPSite osite = new SPSite(properties.WebUrl))
    using (SPWeb sweb = osite.OpenWeb())
        SPList list = sweb.Lists[properties.ListId];
        SPListItem item = list.GetItemByUniqueId(properties.ListItemId);

Code like that

   // Retrieve SPWeb and SPListItem from SPItemEventProperties instead of

// from a new instance of SPSite.
SPWeb web = properties.OpenWeb();
// Operate on the SPWeb object.
SPListItem item = properties.ListItem;
// Operate on an item.

Elevation of Privilege Best Practice

  • Remember that All Elevated Objects Must Remain Inside a RunWithElevatedPrivileges Block.
  •  All Elevated object which created in side the RunWithElevatedPrivileges not  returned to outside of the RunWithElevatedPrivileges block. 
  • If the SPListItem object is passed outside of the RunWithElevatedPrivileges block, it retains its underlying SPRequest object and continues to be elevated. Code that expects to be running under the current user's credentials will have privilege elevation problems if it uses this SPListItem object.


Do not Use RunWithElevatedPrivileges like that

SPSecurity.RunWithElevatedPrivileges(delegate() {

   SPSite osite = SPContext.Current.Site;   

   SPWeb oweb = SPContext.Current.Web;  

// here you need to use oweb object as system user.

        });//Close "SPSecurity.RunWithElevatedPrivileges" block

always use using block with SPSite ,SPWeb   like that

Guid GwebID = SPContext.Current.Web.ID;
Guid GsiteID = SPContext.Current.Site.ID;

    using (SPSite site = new SPSite(GsiteID))
        site.AllowUnsafeUpdates = true;
        using (SPWeb web = site.OpenWeb(GwebID))
            web.AllowUnsafeUpdates = true;
          // Perform administrative actions

   // Handle or re-throw an exception.
   site.AllowUnsafeUpdates = false;

Reference :