Sometimes this works fine and the status of my workflow is "in progress" other times the workflow status gets gets stuck on "starting". The weird part is, when it works fine an exception is thrown when I call StartWorkflow(), when no exception is thrown the status get's stuck on "starting".
Anyone have any ideas
Thanks,
-Somsong

starting workflow programmatically using SPWorkflowManager.StartWorkflow method
english_d
schlrobe
dimkaz
Hi Jon,
Here's my code:
Dim enc As New System.Text.UTF8EncodingDim buffer As Byte() = enc.GetBytes(TextBox1.Text)
Dim site As New SPSite(http://PDCDSP02/0500061)
Dim web As SPWeb = site.OpenWeb
Dim folder As SPFolder = web.Folders("Inspection")
Dim file As SPFile = folder.Files.Add("http://PDCDSP02/0500061/Inspection/Test.xml", buffer)
file.Update()
Dim item As SPListItem = file.Itemitem.Update()
Dim manager As SPWorkflowManager = site.WorkflowManager
Dim workflow As SPWorkflow
workflow = manager.StartWorkflow(item, item.ParentList.WorkflowAssociations(0),
"", True)item.Update()
I don't have an Initiation or Association form so I just pass in "" for the EventData parameter. I'm just not sure why it works sometimes and sometimes it doesn't.
George Waters
Michael Cummings
The exception I get is:
Exception from HRESULT: 0x8102009B
Here's my stacktrace of the exception:
at Microsoft.SharePoint.Library.SPRequest.AddWorkflowToListItem(String bstrUrl, String bstrListName, Int32 lItemID, Int32 lItemLevel, Int32 lItemVersion, Guid workflowPackageId, Guid& pWorkflowInstanceId, Guid workflowTaskListId, String bstrStatusFieldInternalName, Int32 lAuthorId)
at Microsoft.SharePoint.Workflow.SPWorkflowManager.StartWorkflowElev(SPListItem item, SPWorkflowAssociation association, SPWorkflowEvent startEvent, Boolean bAutoStart, Boolean bCreateOnly)
at Microsoft.SharePoint.Workflow.SPWorkflowManager.<>c__DisplayClass1.<StartWorkflow>b__0()
at Microsoft.SharePoint.SPSecurity.CodeToRunElevatedWrapper(Object state)
at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.<RunWithElevatedPrivileges>b__2()
at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)
at Microsoft.SharePoint.Workflow.SPWorkflowManager.StartWorkflow(SPListItem item, SPWorkflowAssociation association, SPWorkflowEvent startEvent, Boolean bAutoStart, Boolean bCreateOnly)
at Microsoft.SharePoint.Workflow.SPWorkflowManager.StartWorkflow(SPListItem item, SPWorkflowAssociation association, String eventData, Boolean isAutoStart)
at WinAppTest.Form1.Button1_Click(Object sender, EventArgs e) in C:\Projects\pdc\R & D\Somsong P\WinAppTest\WinAppTest\Form1.vb:line 22
The weird part is, when I get this exception everything works as it should. When there is no exception the workflow doesn't start properly.