I have the below code but getting Error: 1 : Execute of Activity codeActivity1 threw System.ArgumentException: Argument 'Length' must be greater or equal to zero.
Private Sub codeActivity1_ExecuteCode(sender As System.Object, e As System.EventArgs)
HistoryDescription1 = "STARTING CODE ACTIVITY1"
Dim obj As Object
Dim sSite As String = ""
Dim sList As String = ""
Dim file As SPFile = workflowProperties.Item.File
obj = workflowProperties.Item
Dim areader As StringReader = New System.IO.StringReader(file.ToString)
Dim breader As StreamReader = New StreamReader(Me.workflowProperties.Item.File.OpenBinaryStream)
Dim str As String = breader.ReadToEnd
Dim tempstr As String = ""
Dim listid As String = ""
Dim taskid As String = ""
Dim sEmailBody As String = ""
Dim pos As Integer = 0
Dim aitem As SPListItem
HistoryDescription1 = "STARTING TRY1"
Try
Dim msgObj As New System.Net.Mail.MailMessage
Catch ex As Microsoft.SharePoint.SPException
End Try
Dim testString As String = str
pos = InStr(str, vbCrLf & vbCrLf)
HistoryDescription1 = "STARTING TRY2"
Try
sEmailBody = Mid(str, pos, 100)
Catch ex As Microsoft.SharePoint.SPException
End Try
pos = InStr(str, "Subject: ")
If pos = 0 Then Exit Sub
tempstr = Mid(str, pos + 9, 120)
Dim firstdash = InStr(tempstr, "+")
Dim UserAction = Left(tempstr, firstdash - 1)
tempstr = Right(tempstr, Len(tempstr) - firstdash)
firstdash = InStr(tempstr, "+")
Dim thisTask = Mid(tempstr, 3, firstdash - 3)
tempstr = Right(tempstr, Len(tempstr) - firstdash)
firstdash = InStr(tempstr, "+")
sSite = GetSite(tempstr)
sList = GetList(tempstr)
Dim gList As New Guid(sList)
sList = Replace(sList, " ", "%20")
Dim site As New SPSite(sSite)
Using web As SPWeb = site.OpenWeb()
HistoryDescription1 = "STARTING TRY3"
Try
Dim alist As SPList = web.Lists(gList)
aitem = alist.GetItemById(CInt(thisTask))
If UserAction = "APPROVE" Then
Dim ht As New Hashtable()
ht("Completed") = "TRUE"
ht("PercentComplete") = 1
ht("Status") = "Completed"
ht(SPBuiltInFieldId.WorkflowOutcome) = "Approved"
ht("Outcome") = "Approved"
ht("TaskStatus") = "Approved"
ht(SPBuiltInFieldId.Description) = "Approved by email. User comment: " & sEmailBody
web.AllowUnsafeUpdates = True
SPWorkflowTask.AlterTask(TryCast(aitem, SPListItem), ht, True)
ElseIf UserAction = "REJECT" Then
Dim ht As New Hashtable()
ht("Completed") = "TRUE"
ht("PercentComplete") = 0
ht("Status") = "Completed"
ht("Outcome") = "Rejected"
ht("TaskStatus") = "Rejected"
ht(SPBuiltInFieldId.Description) = "Rejected by email. User comment: " & sEmailBody
ht("FormData") = SPWorkflowStatus.Completed
web.AllowUnsafeUpdates = True
SPWorkflowTask.AlterTask(TryCast(aitem, SPListItem), ht, True)
End If
HistoryDescription1 = "END WORKFLOW. id=" & thisTask & ": list=" & gList.ToString & ": site=" & sSite & ": action=" & UserAction
Catch ex As Microsoft.SharePoint.SPException
HistoryDescription1 = ex.Message
Dim ht As New Hashtable()
ht("Completed") = "FALSE"
ht("PercentComplete") = 0
ht("Status") = "Error"
ht("Outcome") = "Error"
ht("TaskStatus") = "Error"
ht(SPBuiltInFieldId.Description) = "Error: " & ex.Message
ht("FormData") = SPWorkflowStatus.ErrorOccurred
SPWorkflowTask.AlterTask(TryCast(aitem, SPListItem), ht, True)
HistoryDescription1 = sSite & sList
End Try
End Using
End Sub
Private Function GetSite(fullString As String) As String
Dim pos As Integer = InStr(fullString, "SITE")
Dim dsh As Integer = InStr(pos, fullString, "+")
Dim s As String = Mid(fullString, pos + 4, dsh - 5)
HistoryDescription1 = s
Return s
End Function
Private Function GetList(fullString As String) As String
Dim pos As Integer = InStr(fullString, "+LIST")
Dim tmp As String = Mid(fullString, pos + 5, 36)
HistoryDescription1 = tmp
Return tmp
End Function
Private Sub codeActivity1_ExecuteCode(sender As System.Object, e As System.EventArgs)
HistoryDescription1 = "STARTING CODE ACTIVITY1"
Dim obj As Object
Dim sSite As String = ""
Dim sList As String = ""
Dim file As SPFile = workflowProperties.Item.File
obj = workflowProperties.Item
Dim areader As StringReader = New System.IO.StringReader(file.ToString)
Dim breader As StreamReader = New StreamReader(Me.workflowProperties.Item.File.OpenBinaryStream)
Dim str As String = breader.ReadToEnd
Dim tempstr As String = ""
Dim listid As String = ""
Dim taskid As String = ""
Dim sEmailBody As String = ""
Dim pos As Integer = 0
Dim aitem As SPListItem
HistoryDescription1 = "STARTING TRY1"
Try
Dim msgObj As New System.Net.Mail.MailMessage
Catch ex As Microsoft.SharePoint.SPException
End Try
Dim testString As String = str
pos = InStr(str, vbCrLf & vbCrLf)
HistoryDescription1 = "STARTING TRY2"
Try
sEmailBody = Mid(str, pos, 100)
Catch ex As Microsoft.SharePoint.SPException
End Try
pos = InStr(str, "Subject: ")
If pos = 0 Then Exit Sub
tempstr = Mid(str, pos + 9, 120)
Dim firstdash = InStr(tempstr, "+")
Dim UserAction = Left(tempstr, firstdash - 1)
tempstr = Right(tempstr, Len(tempstr) - firstdash)
firstdash = InStr(tempstr, "+")
Dim thisTask = Mid(tempstr, 3, firstdash - 3)
tempstr = Right(tempstr, Len(tempstr) - firstdash)
firstdash = InStr(tempstr, "+")
sSite = GetSite(tempstr)
sList = GetList(tempstr)
Dim gList As New Guid(sList)
sList = Replace(sList, " ", "%20")
Dim site As New SPSite(sSite)
Using web As SPWeb = site.OpenWeb()
HistoryDescription1 = "STARTING TRY3"
Try
Dim alist As SPList = web.Lists(gList)
aitem = alist.GetItemById(CInt(thisTask))
If UserAction = "APPROVE" Then
Dim ht As New Hashtable()
ht("Completed") = "TRUE"
ht("PercentComplete") = 1
ht("Status") = "Completed"
ht(SPBuiltInFieldId.WorkflowOutcome) = "Approved"
ht("Outcome") = "Approved"
ht("TaskStatus") = "Approved"
ht(SPBuiltInFieldId.Description) = "Approved by email. User comment: " & sEmailBody
web.AllowUnsafeUpdates = True
SPWorkflowTask.AlterTask(TryCast(aitem, SPListItem), ht, True)
ElseIf UserAction = "REJECT" Then
Dim ht As New Hashtable()
ht("Completed") = "TRUE"
ht("PercentComplete") = 0
ht("Status") = "Completed"
ht("Outcome") = "Rejected"
ht("TaskStatus") = "Rejected"
ht(SPBuiltInFieldId.Description) = "Rejected by email. User comment: " & sEmailBody
ht("FormData") = SPWorkflowStatus.Completed
web.AllowUnsafeUpdates = True
SPWorkflowTask.AlterTask(TryCast(aitem, SPListItem), ht, True)
End If
HistoryDescription1 = "END WORKFLOW. id=" & thisTask & ": list=" & gList.ToString & ": site=" & sSite & ": action=" & UserAction
Catch ex As Microsoft.SharePoint.SPException
HistoryDescription1 = ex.Message
Dim ht As New Hashtable()
ht("Completed") = "FALSE"
ht("PercentComplete") = 0
ht("Status") = "Error"
ht("Outcome") = "Error"
ht("TaskStatus") = "Error"
ht(SPBuiltInFieldId.Description) = "Error: " & ex.Message
ht("FormData") = SPWorkflowStatus.ErrorOccurred
SPWorkflowTask.AlterTask(TryCast(aitem, SPListItem), ht, True)
HistoryDescription1 = sSite & sList
End Try
End Using
End Sub
Private Function GetSite(fullString As String) As String
Dim pos As Integer = InStr(fullString, "SITE")
Dim dsh As Integer = InStr(pos, fullString, "+")
Dim s As String = Mid(fullString, pos + 4, dsh - 5)
HistoryDescription1 = s
Return s
End Function
Private Function GetList(fullString As String) As String
Dim pos As Integer = InStr(fullString, "+LIST")
Dim tmp As String = Mid(fullString, pos + 5, 36)
HistoryDescription1 = tmp
Return tmp
End Function