I am currently trying to write a custom workflow that reads text data files stored in a CRM record notes section. These files have multiple lines of data and I need to be able to step through the 'file' line by line by line. I have thus far managed to extract the file contents ( including CRLF's ) to a string ( content ). How can I read the 'string' as a file. I know the line length is a constant 91 bytes in length. I have written the content string directly to a txt file and it is perfectly formed, but I'm trying to avoid creating a file on disc just so I can read it with file reader. Is there a way I can read this string ie 91 bytes at a time without writing it to disc first ?
My code so far
Protected Overrides Sub Execute(Executioncontext As CodeActivityContext)
Try
Dim context As IWorkflowContext = Executioncontext.GetExtension(Of IWorkflowContext)()
Dim serviceFactory As IOrganizationServiceFactory = Executioncontext.GetExtension(Of IOrganizationServiceFactory)()
Dim service As IOrganizationService = serviceFactory.CreateOrganizationService(context.UserId)
Dim Notes As QueryExpression = New QueryExpression With {
.EntityName = "annotation",
.ColumnSet = New ColumnSet("filename", "subject", "annotationid", "documentbody", "filename")
}
Notes.Criteria.AddCondition("objectid", ConditionOperator.Equal, context.PrimaryEntityId.ToString)
Dim NotesRetrieve As EntityCollection = service.RetrieveMultiple(Notes)
If NotesRetrieve IsNot Nothing AndAlso NotesRetrieve.Entities.Count > 0 Then
If True Then
Dim fil As Byte() = Convert.FromBase64String(NotesRetrieve.Entities(0).Attributes("documentbody").ToString())
Dim content As String = System.Text.Encoding.UTF8.GetString(fil)
' read the string and process to the relevant entities
End If
End If
Catch ex As Exception
WriteToErrorLog(ex.Message.ToString)
End Try
My code so far
Protected Overrides Sub Execute(Executioncontext As CodeActivityContext)
Try
Dim context As IWorkflowContext = Executioncontext.GetExtension(Of IWorkflowContext)()
Dim serviceFactory As IOrganizationServiceFactory = Executioncontext.GetExtension(Of IOrganizationServiceFactory)()
Dim service As IOrganizationService = serviceFactory.CreateOrganizationService(context.UserId)
Dim Notes As QueryExpression = New QueryExpression With {
.EntityName = "annotation",
.ColumnSet = New ColumnSet("filename", "subject", "annotationid", "documentbody", "filename")
}
Notes.Criteria.AddCondition("objectid", ConditionOperator.Equal, context.PrimaryEntityId.ToString)
Dim NotesRetrieve As EntityCollection = service.RetrieveMultiple(Notes)
If NotesRetrieve IsNot Nothing AndAlso NotesRetrieve.Entities.Count > 0 Then
If True Then
Dim fil As Byte() = Convert.FromBase64String(NotesRetrieve.Entities(0).Attributes("documentbody").ToString())
Dim content As String = System.Text.Encoding.UTF8.GetString(fil)
' read the string and process to the relevant entities
End If
End If
Catch ex As Exception
WriteToErrorLog(ex.Message.ToString)
End Try