Please send me the code to create excel CSV file in workflow SDK script activity. I tried to do it using document .createentry but I get an error in my script 'entry not found'. Thanks
Priya
Please send me the code to create excel CSV file in workflow SDK script activity. I tried to do it using document .createentry but I get an error in my script 'entry not found'. Thanks
Priya
The Laserfiche SDK is used to create Laserfiche entries. If you want to create a CSV file on disk, that would go through one of Microsoft's .Net libraries and is not a Laserfiche issue. Try one of the suggestions on the Microsoft forums.
If you're trying to import a CSV file as the electronic component of a Laserfiche entry, see Bert's example in this thread.
The easiest way to create a file on disk in .Net is with AppendAllText.
Thanks. I want to create a CSV file in workflow and store it in repository. The data for CSV file will come from Laserfiche Form
Priya
Were you able to create a CSV file directly in the repository or do you have to create the CSV on disk first and import it into the repository?
Keith, you should be able to create the CSV file as a memorystream and then import the memorystream so you don't have to create temp files on the harddrive, but I don't have any code examples of doing this.
I was able to figure it out. Here is the code I used to create a CSV in a Workflow SDK Script straight into the repository from a MemoryStream object. No need to save the CSV as a temp file.
Protected Overrides Sub Execute()
'Write your code here. The BoundEntryInfo property will access the entry, RASession will get the Repository Access session
'Wrap the code in a Try/Catch to catch any errors...
'Create variables for connecting to the repository
Dim serverName As String = "LFServer", repoName As String = "LFRepository"
Dim username As String = "Workflow", password As String = "WFPassword"
'Retreive FilePath from the Workflow Token
Dim filePath as String = GetTokenValue("FilePath") 'CSV will be stored in the current folder
Dim folder as FolderInfo
'Declare variables for each column
Dim col1 as String 'Will go in Column1 of the CSV
Dim col2 As String 'Will go in Column2 of the CSV
Dim col3 as String 'Column 3 of the CSV
Dim numRows As Integer = GetTokenValue("RowCount")
'Declare variables for building the CSV file in memory
Dim strm As New MemoryStream
Dim csvWriter As StreamWriter
Dim csvData As StringBuilder
Dim lineText As String
Dim enc As ASCIIEncoding = new ASCIIEncoding()
Try
Dim repository As New RepositoryRegistration(serverName, repoName)
csvData = New StringBuilder() 'We will append all of the data to this string object
'Build the text for the CSV FIle into a StringBuilder object
For Index As Integer = 1 To numRows
col1 = TokenReplace("%(Column1#["+Index.ToString+"]#)")
col2 = TokenReplace("%(Column2#["+Index.ToString+"]#)")
col3 = TokenReplace("%(Column3#["+Index.ToString+"]#)")
lineText = TokenReplace("%(Column1#["+Index.ToString+"]#)"+","+"%(Column2#["+Index.ToString+"]#)"+","+"%(Column3#["+Index.ToString+"]#)")
csvData.AppendLine(lineText)
Next Index
Using session As New Session()
session.LogIn(username, password, repository)
' Create a new csv document in the LF System Accounts folder under the current folder
Dim docInfo As New Laserfiche.RepositoryAccess.DocumentInfo(session)
folder = Laserfiche.RepositoryAccess.Folder.GetFolderInfo(filePath, session)
docInfo.Create(folder, "index.csv", "LF SYSTEM ACCOUNTS", EntryNameOption.AutoRename)
'Create a document importer object and tie it to the newly created csv document
Dim importer as DocumentImporter = new DocumentImporter()
importer.Document = docInfo
'Import the StringBuilder object into a byte array and convert to a MemoryStream
Dim b as Byte() = System.Text.Encoding.UTF8.GetBytes(csvData.ToString())
strm = New MemoryStream(b)
importer.ImportEDoc("text/csv", strm) 'Import MemoryStream into CSV
strm.Close
End Using
'Cleanup...
csvWriter = Nothing
csvData = Nothing
Catch ex As Exception
'Send any error messages to workflow so they can be tracked...
WorkflowApi.TrackError(ex.message)
End Try
End Sub
Make sure you update the Server Name, Repository Name and Credential variables to login to the repository.