Thursday, August 1, 2013

When Integrate SSRS Reports in Sharepoint Page go the error "SharePoint 2010: "Session state has been disabled for ASP.NET. The Report Viewer control requires that session state be enabled in local mode"

Web.config

First, you need to edit the web.config file of the SharePoint application. Open your web.config and add the httpModules
In the <system.web> section, find the <httpModules> element and edit it like the following:
<httpModules> <add name = “Session” type=”System.Web.SessionState.SessionStateModule” /></httpModules>

You also need to find the element tag <pages> (also under the <system.web> element) and look for the attribute called enableSessionState and set it to true if it is currently false. Save and close the web.config file.


IIS7

  • You should then open the IIS 7 manager, and select your web application.
  • Open the modules applet under the IIS section.
  • Click “Add Managed Module” in the right hand panel.
  • Enter a name for the module, I chose “SessionState”, you can pick what you like, but I suggest something related to session state and then in the lower box, select the entry for:
System.Web.SessionState.SessionStateModule, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Made an IISreset, and test again. you can now add your WebPart Report Viewer control to your site.

Sharepoint Tips

Sharepoint Tips

Calulated Cloumns: 
 For Number column for left aligning
=IF([Source Column]<>"",[Source Column],"") 
For Currency field use below
=IF([Source Column]<>"","$" & [Source Column],"") 
For percentage Use this
=IF([Source Column]<>"",[Source Column]*100&"%","") 
 Below is the list of pages & their paths which can be accessed from URL :

· Add web parts to any page: append ?PageView=Shared&ToolPaneView=2

· Create New Site Content /_layouts/create.aspx
· Create New Site: _layouts/NewsbWeb.aspx
· List Template Gallery: _catalogs/lt/Forms/AllItems.aspx
· Master Page Gallery: _catalogs/masterpage/Forms/AllItems.aspx
· Manage your Alerts _layouts/SubEdit.aspx
· Create New Alert: _layouts/SubChoos.aspx
· Manage Site Collection Administrators /_layouts/mngsiteadmin.aspx
· Manage Sites and Workspaces /_layouts/mngsubwebs.aspx
· Manage People /_layouts/people.aspx
· Manage User Permissions /_layouts/user.aspx
· Modify Navigation /_layouts/AreaNavigationSettings.aspx
· Modify Site Navigation: _layouts/SiteNavigationSettings.aspx
· Recycle Bin /_layouts/AdminRecycleBin.aspx
· Site Directory _layouts/SiteDirectorySettings.aspx
· Save Site as Template: _layouts/savetmpl.aspx
· Site Settings page: _layouts/settings.aspx
· Create New Web Part Page: _layouts/spcf.aspx
· Site Template Gallery : _catalogs/wt/Forms/Common.aspx
· Site Column Gallery /_layouts/mngfield.aspx
· Site Content Types /_layouts/mngctype.aspx
· Site Content and Structure Manager /_layouts/sitemanager.aspx
· Site Usage Summary /_layouts/SpUsageWeb.aspx
· User Alerts /_layouts/sitesubs.aspx
· View All Site Content /_layouts/viewlsts.aspx
· Web Part Gallery: _catalogs/wp/Forms/AllItems.aspx
· Web part maintenance mode: append ?contents=1 to the URL of the page
· Open the page in Edit Mode: In Address bar, Type "javascript:MSOLayout_ToggleLayoutMode();"
or "javascript:MSOTlPn_ShowToolPane(’2′);" in the Address bar
· Add Web Parts Pane: ?ToolPaneView=2

Thursday, July 18, 2013

Update() VS System.Update()

 

1 using (SPSite siteObj = new SPSite("http://hydpc1129:9999/ITS/"))
2         {
3            using (SPWeb webObj = siteObj.OpenWeb())
4           {
5              SPList empListObj = web.GetList("LegalContracts");
6          SPListItem empItem = empListObj.Items.Add();
7           empItem["Title"] = "Emp1";
8       empItem["Department"] = "Finance";
9       empItem.Update();
10       //empItem.SystemUpdate();
11      //empItem.SystemUpdate(true);
12      //empItem.SystemUpdate(false);
         }
       }

 

Update

In the above code, Line 9 empItem.Update() will update the “EmpList” data. This will also update the built in columns “Modified” and “Modified By”.

SystemUpdate

If we are using Line 10 empItem.SystemUpdate(); this will update the “EmpList” data but not the built in columns “Modified” and “Modified By”.
If we are using Line 11 empItem.SystemUpdate(true);this will update the “EmpList” data but not the built in columns “Modified” and “Modified By”. But it will increment the item version
If we are using Line 12 empItem.SystemUpdate(false);this will update the “EmpList” data but not the built in columns “Modified” and “Modified By”. Also, does not increment the item verision

SystemUpdate will trigger all the list events if any and also the changes can be observed in Audit logs. Only alerts will not be triggered that are configured on the list.
Note:
If we are using SharePoint model, we are flexible to use any of the methods as per our requirement.
But, if we are using client object model only Update method will be available, SystemUpdate method will not be available. Its obvious that SystemUpdate method is not available because, clients are updating the database data and server should be aware of this(though logs are still updated).
I think that is good reason why client object model does not expose SystemUpdate method

Tuesday, June 4, 2013

The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.

The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.

The above error will be thrown at the time of updating Library or Lists items due to authentication problem, or We didn’t have the rights to update the items.
By using the following code, We can overcome this issue,

Web.AllowUnsafeUpdates = true;
item["Title"]=”ConfigList”;
item.Update();


or we can also use the following code to overcome the above error, this will affect the WebApplication. This will change the Security settings of a Web Application to allow the anonymous user to update item.

web.Site.WebApplication.FormDigestSettings.Enabled = false;
item["Title"]=”
ConfigList”;
item.Update();
web.Site.WebApplication.FormDigestSettings.Enabled = true;


or we can change the settings in Central Administration to anonymously update the items. But this method will be dangerous.

  • Central Administration > Application Management > Web Application General Settings
  • Choose the WebApplication to overwrite the settings
  • Select the option Off in Web Page Security Validation as follows,
securitysettings1

Other possible ways you can try:

1. Set AllowUnsafeUpdates property of SPWeb / SPSite to true
2. Set web.Site.WebApplication.FormDigestSettings.Enabled to false
3. writing code inside SPSecurity.RunWithElevatedPrivileges()
4. using WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate()
5. Changing authentication provider in Central Administration
Central Administration > Application Management > Authentication Providers
 Select “Zone”
 Check “Enable Anonymous Access”
6. Turn off Web Page Security Validation in Central Administration
Central Administration > Application Management > Web Application General Settings
 Select the option Off in Web Page Security Validation

But turn off the security validation from Central Administration is not the safe way to do it.

Monday, June 3, 2013

The security validation for this page is invalid" error when updating objects through SharePoint object model

This error is often encountered when SharePoint OM is used to update site/web/list objects from within a web context.  Some thing so basic as the code below could fail:

using (SPSite site = new SPSite("http://hydpc1129"))
{
    using (SPWeb web = site.OpenWeb())
    {
        SPList list = web.Lists["ConfigList"];
        list.Title = "Admin";
        list.Update();
        web.Update();
    }
}

Setting the "AllowUnsafeUpdates" properties of both the SPSite and SPWeb objects to "true", mostly will resolve this issue out if you are using a code similar to above within a webpart or an ASP.NET web application.  When you are running from the context of a separate web application make sure the application pool identity running your ASP.NET web application is the same as the one that's running SharePoint's site.  Below is a code that fixes the "security validation for this page is invalid" error.

using (SPSite site = new SPSite("http://hydpc1129"))
{
    site.AllowUnsafeUpdates = true;
    using (SPWeb web = site.OpenWeb())
    {
        web.AllowUnsafeUpdates = true;
        SPList list = web.Lists["ConfigList"];
        list.Title = "Admin";
        list.Update();
        web.Update();
    }
}

Adding Authenticated Users to Sharepoint Group


SPWeb grpWeb = properties.Parent as SPWeb;
string strPermissionLevel = "Read";
grpWeb .SiteGroups.Add("PMOGroup", owner, owner, "PMOUsers");
SPRoleAssignment roleAssignment = new SPRoleAssignment(grpWeb .SiteGroups["PMOGroup"]);
roleAssignment.RoleDefinitionBindings.Add(grpWeb .RoleDefinitions[strPermissionLevel]);
grpWeb .RoleAssignments.Add(roleAssignment);
grpWeb .Update();

// "c:0(.s|true" = All authenticated users

grpWeb .SiteGroups["PMOGroup"].AddUser("c:0(.s|true", string.Empty, string.Empty, string.Empty)

Friday, May 24, 2013

Error occurred in deployment step ‘Activate Features’: 0×80070002

Sol1:The target List was incorrect and the solution was to simply include the correct ListUrl in the receivers element in element.xml as <Receivers ListUrl=”/Lists/myList”

Sol2: A quick way is to set the value of the active deployment configuration from Default to No Activation (in the properties of the project). That way you need to manually activate your features and you can directly see what goes wrong

Thursday, February 7, 2013

The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.



If we get the above error in SharePoint, you need to add one tag in the aspx page,
 using Microsoft.SharePoint.Utilities;
<SharePoint:FormDigest ID="FormDigest1" runat="server" />

protected override void OnInit(EventArgs e)
        {
            if (Page.IsPostBack)
                SPUtility.ValidateFormDigest();
            base.OnInit(e);
        }