You are viewing limited content. For full access, please sign in.

Question

Question

Attaching a Text File as an Electronic Document to an Entry via Workflow

asked on December 8, 2023

I have multiple workflows that create an entry in the repository and attach text to that entry via the page text functionality.  Some of these are basic text, some are formatted as CSV data, and some is HTML code.

I am using Scripting activities to attach the text to the entries.

This works, but it isn't completely ideal for every case, particular the CSV and HTML use cases.  In order to work with the data later on, it has to be copied out of the repository and saved as a text file with a CSV or HTML file extension in order to view it "normally".

It would be so much better if I could create the text file in Workflow, with the proper file extension, and then attach it to the entry as an electronic document.  But I can't figure out how to do that.

I do have experience creating Word documents and attaching those using the built-in activities in Workflow, but there doesn't seem to be any activities for other types of files, like text, CSV, or HTML files.

Does anyone have any experience with this, or have any suggestions on how something like that might be possible?

Thank you!

0 0

Answer

SELECTED ANSWER
replied on December 8, 2023

You can use the WriteEdoc method in a script activity to attach pretty much whatever file type.

The following is from code I use to pre-generate a PDF from native pages and attach it back to the entry; the only difference would be the mimetype parameter and the extension.

var bytes = ms.ToArray();
using(Stream eDocStream = doc.WriteEdoc("application/pdf",bytes.LongLength)){
    eDocStream.Write(bytes,0,bytes.Length);
}

// Update document extension and save changes
doc.Extension = ".pdf";

// Save changes
doc.Save();

In this example, I'm exporting a PDF out to a memory stream, then writing that file back to the document. In your case, you would do something similar with the text file you generate.

4 0
replied on December 11, 2023

Awesome!  Thank you @████████

I'll play around with this and respond back.

0 0
replied on December 11, 2023

That worked perfectly for a TXT file and an HTML file.  I now have a simple script that can take a token of text and turn that into a TXT file, or an HTML file exactly as I needed.

It didn't work on my first try as a CSV file, but I may just be doing something silly, so I'll revist that later.

Thank you again!

0 0
replied on December 12, 2023

For the record - it works fine with CSV files too - it's just Excel being a jerk and deciding that comma-separated doesn't actually mean comma-separated.  If I am working on a file that will be used within Excel, I can get around this by adding   SEP=,   to the start of the file I am creating to tell Excel that it is actually comma-seaparated.  That's a stupid workaround, and would cause issues with the file being used in other contexts that don't know about that being in the first line, but it gets the issue worked out for Excel at least.  Ugh.

1 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.