Month: December 2013

Extension methode for web.AllowUnsafeUpdates

How we do it:

using (SPSite site = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWebweb = site.OpenWeb())
                {
                        web.AllowUnsafeUpdates = true;
                        SPList list = web.Lists.TryGetList(“TestExtensionList”);
                        SPListItem item = list.Items.Add();
                        item[SPBuiltInFieldId.Title] = TextBox1.Text.Trim();
                        item.Update();
                        web.AllowUnsafeUpdates = false;
                }

            }

How we can do it:

using (SPSite site = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWebweb = site.OpenWeb())
                {
                    web.DoUnsafeUpdate(delegate()
                    {
                        SPList list = web.Lists.TryGetList(“TestExtensionList”);
                        SPListItem item = list.Items.Add();
                        item[SPBuiltInFieldId.Title] = TextBox1.Text.Trim();
                        item.Update();
                    });  
                }
            }

Extension Methode to achieve the above code pattern:

public static class ExtensionMethodeClass

    {
        public static void DoUnsafeUpdate(thisSPWeb web, Actionaction)
        {
            bool allowUnsafeUpdates = web.AllowUnsafeUpdates;
            web.AllowUnsafeUpdates = true;
            action();
            web.AllowUnsafeUpdates = allowUnsafeUpdates;
        }
    }

SharePoint connected Web Part not showing connections option

Possible reasons include the following:

  • You are not browsing a web part in edit mode. To set connection with other web part, Page should be in edit mode.
  • Web part connection not allowed in the Web Application. To enable web part connection follow below steps: 1)   Open the central administration
    2)   Application management
    3)   Web applications
    4)   Manage web applications
    5)   Select the web application for which you would like to enable the option
    6)   On the top-Ribbon-You will find an option as ‘webpart security’
    7)   Click on it and you will get one frame window which specifies ‘security for web pages
    8)   Here you will find the option of Web part connections
    9)   Select the option “Allows users to create connections between Web Parts”
    1)   Open the central administration
    2)   Application management
    3)   Web applications
    4)   Manage web applications
    5)   Select the web application for which you would like to enable the option
    6)   On the top-Ribbon-You will find an option as ‘webpart security’
    7)   Click on it and you will get one frame window which specifies ‘security for web pages
    8)   Here you will find the option of Web part connections
    9)   Select the option “Allows users to create connections between Web Parts”

    – See more at: http://sharepointknowledgebase.blogspot.in/2013/09/webpart-security-disable-web-part.html#sthash.gSlOHy8q.dpuf

    1)   Open the central administration
    2)   Application management
    3)   Web applications
    4)   Manage web applications
    5)   Select the web application for which you would like to enable the option
    6)   On the top-Ribbon-You will find an option as ‘webpart security’
    7)   Click on it and you will get one frame window which specifies ‘security for web pages
    8)   Here you will find the option of Web part connections
    9)   Select the option “Allows users to create connections between Web Parts”

    – See more at: http://sharepointknowledgebase.blogspot.in/2013/09/webpart-security-disable-web-part.html#sthash.gSlOHy8q.dpuf

  • The web part is not added to Web Part Zone. The page should be Web part Zone Page.

More at:

You can find few more at:
http://technet.microsoft.com/en-us/library/cc767503.aspx