Tuesday, January 29, 2013

How to fix: "The security validation for this page is invalid." error

When you want to programmatically update a column for a list or library item, an error similar to the below might be thrown.
The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.
Now, I have many web methods which are updating many different libraries in my site, but this particular issue occurred on one of the web methods connected to one particular library. Though I have not been able to understand why, but I was able to resolve the issue by using the following command.
myWeb.AllowUnsafeUpdate = true;
myListItem["Status"] = "Approved";
myListItem.Update(); 
I still want to know the reason why only one of the web method and library needed this extra piece of code? All other web methods are updating library items without the use of this code.

I would appreciate your comments if you may know the reason for this. If you have found this helpful, let me know that too :)

Monday, January 14, 2013

How to fix: "Unable to display this Web Part" when you want to initiate a workflow manually

Issue

This was a recent encounter (error message below) while starting a Workflow manually in MOSS (SharePoint 2007).

Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.

For your better understanding, let me first explain you where I was at, and where I was heading. I wanted to start a workflow manually on a Document Library. [That wasn't tough :)]

I navigated to the:

  • Document Library >
  • Library Item >
  • Edit Menu >
  • Click on Workflows.
  • Under Start a New Workflow section, I clicked on the Workflow and was eye to eye with the error.

Analysis

As the error was instructing me to use SharePoint Designer, so I opened. And since this was a web part that was failing, I thought if I could remove the web part from the page and add it again. This was my source of greater understanding.

But since this was related to Workflows, I opened the particular workflow that was failing and noticed an .aspx page in the bundle (as below). This ASPX page represents the page that we use to manually run the workflow.

Resolution

I backed up this .aspx page, merely by changing its name. I then opened the Workflow (.xoml file) and published it. This action created a new ASPX page for me.

Now when I clicked on Start a New Workflow, the page appeared fine and I was able to run the workflow.