Pages

Tuesday, January 26, 2010

How to terminate/cancel workflow from SharePoint object model

While terminating or cancelling workflow, it will delete all the tasks from the task list and it will marked task status as “Cancelled” into attached list.

Reference Link:

http://blog.brianfarnhill.com/2008/10/01/how-to-cancel-a-workflow-programmatically/

Visual Studio Approval Workflow Example

http://msdn.microsoft.com/en-us/library/dd674137.aspx

http://msdn.microsoft.com/en-us/library/cc811589.aspx

How to get workflow instance for single workflow into listitem

http://nishantrana.wordpress.com/2009/02/10/using-workflow-object-model-in-sharepoint/

Getting access denied error while updating list items

I was getting access denied error while updating list items, I already tried to put my code into SPSecurity.RunWithElevatedPrivileges delegate, still I was getting error. Below was my actual code.

CODE:

//code line for updating list columns

Listitem.update()

List.Update()

After doing debugging and removing line by line from actual code I have figured out actual problem – the user who has contributor rights(normal user) was getting access denied error, admin users can able to update list without any problem, it’s because of LIST.UPDATE() statement, because contributor rights users don’t have permission to change anything into List settings, they can add/delete list items but they can’t able to change anything into list, after removing LIST.UPDATE() statement from my actual code, all users were able to successfully update the list items.

Enjoy!

How to attach/delete attachments from SharePoint list items

http://www.pointsharepoint.com/2008/12/list-attachments-in-webpart-solution.html

ERROR: Workflow failed on start

I was getting below error while starting of workflow.

Workflow:System.Workflow.ComponentModel.Compiler.WorkflowValidationFailedException: The workflow failed validation.     at System.Workflow.Runtime.WorkflowDefinitionDispenser.ValidateDefinition(Activity root, Boolean isNewType, ITypeProvider typeProvider)     at System.Workflow.Runtime.WorkflowDefinitionDispenser.LoadRootActivity(Type workflowType, Boolean createDefinition, Boolean initForRuntime)     at System.Workflow.Runtime.WorkflowDefinitionDispenser.GetRootActivity(Type workflowType, Boolean createNew, Boolean initForRuntime)     at System.Workflow.Runtime.WorkflowRuntime.InitializeExecutor(Guid instanceId, CreationContext context, WorkflowExecutor executor, WorkflowInstance workflowInstance)     at System.Workflow.Runtime.WorkflowRuntime.Load(Guid key, CreationContext

I spend lots of time to find out exact resolution for workflow failed error, but I couldn’t get solution, below are some of the reference link which talks causing of issue due to migration from visual studio 2005 to 2008 workflow project, but in my case, I have created workflow into visual studio 2008 only, some articles were talking about adding some line into solution project, but that’s also not working for me.

Reference Link:

http://blog.hhebnes.no/?tag=/workflows

http://www.eggheadcafe.com/software/aspnet/31975863/sharepoint-workflow-upgra.aspx

http://geekswithblogs.net/SoftwareDoneRight/archive/2007/12/12/condition-not-found.aspx

At the last for resolving my issue, I have created new workflow file, one thing I have observed here – if I am going to change main default file name for workflow file from workflow.cs to something else, then sometime it will mess up workflow. So I would recommend not changing workflow.cs file name.

:)

How to get current status of workflow from SharePoint object model

Reference Link:

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.workflow.spworkflowstatus.aspx

Sample Code:
//Obtain a list item
SPWeb thisWeb = SPControl.GetContextWeb(Context);
SPList issuesList = thisWeb.Lists["Customer Issues"];
SPListItem myItem = issuesList.Items[0];
//Get the workflow status value
int WorkflowStatusValue = myItem["MyWorkflow"];
string WorkflowStatusString = System.Enum.GetName
        (typeof(SPWorkflowStatus), WorkflowStatusValue);
StatusLabel.Text = "The current status of the workflow is: " +
        WorkflowStatusString;

SPWorkflow AlterTask didn’t work with hash table which has space into key name

While creating hash table for passing into altertask method, we need to be very careful, because it didn’t like spaces into key name, we need to put our key without spaces.

Sample Code:

taskHash["UserInputField"] = UserInputField.Text;

taskHash["UserInputField_ForHash"] = UserInputField.Text;

taskHash["Status"] = "Completed";

taskHash["Status_ForHash"] = "Completed";

SPWorkflowTask.AlterTask(taskListItem, taskHash, true);

Reference Link:

http://www.databaseforum.info/10/1131769.aspx

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

I was getting above error while doing altertask on SPWorkflowTask.AlterTask method.

Solution:  we need to write altertask code under SPSecurity delegate and need to write code for Allowunsafeaccess.

http://sansanwal.blogspot.com/2009/08/security-validation-for-this-page-is.html

http://support.microsoft.com/default.aspx?scid=kb;EN-US;970192

ERROR: The content type of a workflow task must be derived from the Workflow Task content type

I was getting “The content type of a workflow task must be derived from the Workflow Task content type” error while working with custom ASPX form for visual studio workflow, I have created custom content type which will be used into workflow, I have found out that my content type ID is incorrect by comparing it with some another content type ID. Visual studio activity “Createtaskwithcontenttype” must be inherited from workflow task.

Reference Links:                                

http://www.eggheadcafe.com/software/aspnet/30858987/login.aspx

http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/93679b02-bfa9-43c2-94ad-ec45191cd478