Monday, December 16, 2013

Extension methode for web.AllowUnsafeUpdates


How we do it:

using (SPSite site = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWeb web = 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 (SPWeb web = site.OpenWeb())
                {
                    web.DoUnsafeUpdate(delegate()
                    {
                        SPList list = web.Lists.TryGetList("TestExtensionList");
                        SPListItem item = list.Items.Add();
                        item[SPBuiltInFieldId.Title] = TextBox1.Text.Trim();
                        item.Update();
                    });  
                }
            }

Tuesday, December 3, 2013

Creating connected web part in SharePoint 2010

Steps:
1. Create interface.
2. Create provider web part by implementing the interface created.
3. Create consumer web part.


Code blocks below:-


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:


SharePoint document metadata not updating

I faced a weird issue today, Metadata for document which has lookup column was not updating even after saving the item. There was no erro...