Search This Blog

Friday, November 4, 2011

SharePoint 2010 Easy Setup Script


The SharePoint 2010 Easy Setup Script will enable you to easily build your developer machine. Here is the link http://www.microsoft.com/download/en/details.aspx?id=23415

Tuesday, June 14, 2011

Blocking access to application pages (_layouts) and Forms Pages

All the pages having _layouts before them are application pages. Pages created automatically for various views are called Form Pages. Most often with SharePoint implementation we allow users to access these pages. However we may further want to cut down access of users from the application pages and the form pages.

SharePoint allows this by enabling the feature “ViewFormPagesLockDown”. This feature is activated at the Site Collection scope. All groups / users not having the “View Application Pages” permission will not be able to navigate to pages like “_layouts/viewlsts.aspx” or “pages/forms/allitems.aspx”.
Below are the steps to block access from application pages:

  1. Identify users / group to restrict.
  2. Set their permission to "Restricted Read" or remove the "View Application Pages" from existing assigned permission level.
  3. Enable "ViewFormPagesLockDown" feature using the command - stsadm -o activatefeature -url "SiteCollectionURL" -filename ViewFormPagesLockDown\feature.xml
The above steps will block all users not having "View Application Pages" permission from accessing the application pages and form pages.

Sunday, April 3, 2011

Click event stopped firing after ajax postback

I had a user control on a SharePoint master page for one our client portal which was taking longer to load than other modules on the pages. 

Deciding to load this control asynchronously to speed up the page load I achieved this by adding button control inside the Ajax update panel. This button remains hidden from users view. I made the button click event to fire using JavaScript function by pushing it to body onload event using SharePoint's _spBodyOnLoadFunctionNames function.

The control worked as expected, causing the button click event to fire and processing the server side logic. However, the other buttons, link buttons and other server on other modules lost their events. Now nothing happens whenever I click on any server side button controls.

We tried various different options like calling the JavaScript function right into the script tag, mentioning it on the master page’s body onload event etc,. The final one which worked was ScriptManager's registerstartupscript function i.e. ScriptManager.RegisterStartupScript on the server side page load event. I registered the JavaScript function call using the RegisterStartupScript function provided by ScriptManager object. Now the page worked perfectly without any issue. Buttons, hyperlink buttons all worked smoothly.

I am still not sure what caused events to break by calling the function right into the page load. Your suggestions and advice are welcome.

Saturday, March 19, 2011

Updating List Item from Workflow and avoid repeated firing of workflow

I have a list having a custom workflow attached to it. Workflow is executed whenever any updates are done to the item. Apart from performing various other task, the workflow also need to update a field of that item.

So what is the problem?

There is no issue updating any item from the workflow. You can use workflowProperties.Item["FieldName"] = "Value" to update any field. The side effect is updating the item triggers the workflow again as it is configured to execute when item is modified. This causes the workflow to run in indefinite loop.
So what is the solution?

Create a new class within the workflow and inherit it with SPItemEventReceiver. Create two new functions called DisableWorkflow() and EnableWorkflow().

Inside DisableWorkflow() add a line –
this.DisableEventFiring

Inside EnableWorkflow() add a line –
this.EnableEventFiring

That’s it, just create a object of this class, call DisableWorkflow() just before workflowProperties.Item.Update() .Then call EnableWorkflow() after updating the item.

Saturday, February 26, 2011

Solution to error "Security Validation for this page is invalid"

Few days back I came across this issue. It popped up whenever the page is posted back to update content to the site. On further digging into it I found this was somewhat related to the action performed within elevated code(i.e. code within SPSecurity.RunWithElevatedPrivileges).

SharePoint keep track of the requests using the token unique to the user and his request. Whenever the code is elevated the context is changed from the user to the system account.


To ensure smooth operation without the Security Validation error we should add SPUtility.ValidateFormDigest() line just before elevating the code. This MSDN article also talks about the same.