Thursday, June 20, 2013

WebProvisioned web event - Feature Stapling - sharepoint 2010

WebProvisioned web event receiver -allow to add new additional logic when a site is created-is a new receiver type in SharePoint 2010. This operates at site collection level only.
<Receivers Scope="Site">
You can specify scope to "Site" or "Web" & acoordingly receiver will act SPSite.EventReceivers or SPWeb.EventReceivers

Feature Stapling -allow to add new additional logic when a site is created- will affect whole farm.

Saturday, June 15, 2013

SharePoint 2010 Property Bag - Read / Write data to Property Bag


Property Bag = hash table of Key-Value pairs

Read / Write data to Property Bag

SPSecurity.RunWithElevatedPrivileges(delegate()
        {
        try
        {
            using (SPSite RootSite = new SPSite(URL))
            {
                using (SPWeb SiteCollection = RootSite.OpenWeb())
                {                   
                    try
                    {
                        SiteCollection.AllowUnsafeUpdates = true;
                       // Get connection string from Property bag
                        if (SiteCollection.AllProperties.ContainsKey("ConnectionString"))
                        {
                            ConnectionString = SiteCollection.AllProperties["ConnectionString"].ToString();
                        }                       
                        // Set siteID in the Property bag
                        SiteCollection.Properties["siteID"] = siteID;
                        SiteCollection.Properties.Update();
                        SiteCollection.AllowUnsafeUpdates = false;                       
                    }
                    catch (Exception ex)
                    {
                      //Handle Exception 
                    }          
                }
            }
        }
        catch(Exception ex)       
        {           
        }
        }); 


http://pbs2010.codeplex.com/

Wednesday, June 12, 2013

SandBoxSolution - Full trust proxies in SharePoint 2010

Sandboxed solution is completely isolated to its site collection only a subset of the Microsoft.SharePoint object model is avail - Only objects that operate within the current site collection are available.

Sandbox runs within process - Sandbox Worker Process (SPUCWorkerProcess.exe)

sandbox worker process makes sure to enforce the limits of a Code Access Security (CAS) policy on the contents of the solution
  • SharePointPermission.ObjectModel
  • SecurityPermission.Execution
  • AspNetHostingPermission.Level = Minimal
A Proxy Class has to be deployed at Farm level and can be used by everybody within the farm.
The full trust proxy solution exists of two classes:
The first class inherits from SPProxyOperation, the second class inherits from SPProxyOperationArgs.
Both of these are located in the Micorosft.SharePoint.UserCode namespace.
The class which inherits from SPProxyOperation implements the actual operation the full trust proxy solution has to perform.
The class which inherits from SPProxyOperationArgs defines the arguments which will be passed to the operation. 

When you redeploy your full trust proxy solution you have to restart the User Code Service

Sandbox solution runs under SPUserWorkerProcess.exe, but the full-trust proxy runs under SPUserCode.exe.

…To restart go to the Central Administration, Application Management, Manage services on server and find the Microsoft SharePoint Foundation Sandboxed Code Service. Stop and start this service again. Another option is to use “net stop SPUserCodeV4″, and start it again by using “net start SPUserCodeV4″.

Use SPUtility.ExecuteRegisteredProxyOperation to call code in full trust proxy.


Tuesday, June 11, 2013

CreateChildControls EnsureChildControls RenderControl

CreateChildControls intended to build control – receives and process their events and go through page life cycle.

The EnsureChildControls method ensures that the CreateChildControls method has finished executing. If not, it waits for that method to complete. this.EnsureChildControls();

RenderControl method should only render final html. RenderControl - Outputs server control content and stores tracing information about the control if tracing is enabled.
Do NOT use Render method as it will break sharepoint DOM (break webpart html rendering table)

delegate control in sharepoint 2010

SharePoint allows to customize OOTB functionality without the need for modifying the pages that come with SharePoint with mechanism called “delegate controls”.
A delegate control defines a region in an aspx page that allows the content to be replaced with our custom content.  This custom content is created via a SharePoint feature, and when deployed and activated, replaces the standard content at runtime.

For eg.
<SharePoint:DelegateControl runat="server" ControlId="PageHeader">
</SharePoint:DelegateControl>

ControlId attribute - the Feature we create will use this to substitute the real user/server control
                1)      Create control template under 14 hive
                2)      Create module to add control template
a.  <Control Id="PageHeader" Sequence="90" ControlSrc="~/_ControlTemplates/COBPageHeader.ascx" />
</Elements>
3)      Add module to feature
4)      Deploy
5)      Now custom control result should be reflected instead of standard output of PageHeader
6)      Happy Ending J