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




Monday, June 10, 2013

Show/Hide controls/elements based on user permission in sharepoint 2010

<Sharepoint:SPSecurityTrimmedControl runat="server" Permissions="ManageLists">
Put Your Control Here
</SharePoint:SPSecurityTrimmedControl>
Following are possible Permissions values :
EmptyMask – Has no permissions on the Web site. Not available through the user interface. ViewListItems – View items in lists, documents in document libraries, and view Web discussion comments. AddListItems – Add items to lists, add documents to document libraries, and add Web discussion comments. EditListItems – Edit items in lists, edit documents in document libraries, edit Web discussion comments in documents, and customize Web Part Pages in document libraries. DeleteListItems – Delete items from a list, documents from a document library, and Web discussion comments in documents. ApproveItems – Approve a minor version of a list item or document. OpenItems – View the source of documents with server-side file handlers. ViewVersions – View past versions of a list item or document. DeleteVersions – Delete past versions of a list item or document. CancelCheckout – Discard or check in a document which is checked out to another user. ManagePersonalViews – Create, change, and delete personal views of lists. ManageLists – Create and delete lists, add or remove columns in a list, and add or remove public views of a list. ViewFormPages – View forms, views, and application pages, and enumerate lists. Open – Allow users to open a Web site, list, or folder to access items inside that container. ViewPages – View pages in a Web site. AddAndCustomizePages – Add, change, or delete HTML pages or Web Part Pages, and edit the Web site using a SharePoint Foundation–compatible editor. ApplyThemeAndBorder – Apply a theme or borders to the entire Web site. ApplyStyleSheets – Apply a style sheet (.css file) to the Web site. ViewUsageData – View reports on Web site usage. CreateSSCSite – Create a Web site using Self-Service Site Creation. ManageSubwebs – Create subsites such as team sites, Meeting Workspace sites, and Document Workspace sites. CreateGroups – Create a group of users that can be used anywhere within the site collection. ManagePermissions – Create and change permission levels on the Web site and assign permissions to users and groups. BrowseDirectories – Enumerate files and folders in a Web site using Microsoft Office SharePoint Designer 2007 and WebDAV interfaces. BrowseUserInfo – View information about users of the Web site. AddDelPrivateWebParts – Add or remove personal Web Parts on a Web Part Page. UpdatePersonalWebParts – Update Web Parts to display personalized information. ManageWeb – Grant the ability to perform all administration tasks for the Web site as well as manage content. Activate, deactivate, or edit properties of Web site scoped Features through the object model or through the user interface (UI). When granted on the root Web site of a site collection, activate, deactivate, or edit properties of site collection scoped Features through the object model. To browse to the Site Collection Features page and activate or deactivate site collection scoped Features through the UI, you must be a site collection administrator. UseClientIntegration – Use features that launch client applications; otherwise, users must work on documents locally and upload changes. UseRemoteAPIs – Use SOAP, WebDAV, or Microsoft Office SharePoint Designer 2007 interfaces to access the Web site. ManageAlerts – Manage alerts for all users of the Web site. CreateAlerts – Create e-mail alerts. EditMyUserInfo – Allows a user to change his or her user information, such as adding a picture. EnumeratePermissions – Enumerate permissions on the Web site, list, folder, document, or list item. FullMask – Has all permissions on the Web site. Not available through the user interface.