K2CaveMen
Novice

I need to generate a Text File from a K2 Form.... similar to the PDF Control but as Text File...

Guys, currently there is a need to create a Text File from the input entered by the user in a form. this should generate a Text File with the appropiate information, and like to store and email as attachment.

 

I wonder if somebody have some suggestions on how to achieve this... 

 

Best Regards Dino.

0 Kudos
Reply
3 Replies
FromKtoZ1
Novice

Re: I need to generate a Text File from a K2 Form.... similar to the PDF Control but as Text File...

Hey Dino,


 


I ran quick search to see if anyone else has attempted this. I was able to find this link to another community post where the customer wanted to read and write to a text file:


 


https://community.k2.com/t5/General/Read-and-Write-to-a-TEXT-file-From-SmartForm/td-p/102100


 


I looked around my environment and attempted a few workarounds; however, I do not think this is possible the  out-of-the-box K2. 

0 Kudos
Reply
K2CaveMen
Novice

Re: I need to generate a Text File from a K2 Form.... similar to the PDF Control but as Text File...

So I did create 2 Columns in the SQL Table... 

 

some_text varchar(max)

some_attachment nvarchar(max)

 

When insert the text... in the control ....

!

Some_TEXT

!

 

Upload the same config.txt into the Attachment control...

Later query the Table directly in SQL turn out to have some sort of encoding...

<file><name>config.txt</name><content>IQ0KaG9zdG5hbWUgVEVTVA0KRE5TIDEwLjIzNi4wLjYxDQoh</content></file>

That makes me wonder if somehow can figure it out the encoding and compose the data to insert directly without using the File Control from K2 perhaps might be able to compose the string to be inserted and expet the K2 List to read it later....

 

 

0 Kudos
Reply
ThinusC
Nintex Employee
Nintex Employee

Re: I need to generate a Text File from a K2 Form.... similar to the PDF Control but as Text File...

Hi Dino


 


The File Attachment control saves the file content as a Base64 encoded string.


 


You should be able to insert text as File Attachment control usable content using a Stored Procedure.


 


Something like


CREATE PROCEDURE [dbo].[StringtoK2File]
@Filename nvarchar(50),
@String nvarchar(MAX)
AS
BEGIN

DECLARE @K2File nvarchar(MAX), @Encoded nvarchar(max)

SET @Encoded = (SELECT CAST(@String as varbinary(max)) FOR XML PATH(''), BINARY BASE64)

SET @K2File = (SELECT '<file><name>' + @Filename + '</name><content>'+ @Encoded + '</content></file>')

INSERT INTO [dbo].[MyFiles] ([Text], [MyK2File],) VALUES (@String,@K2File)

END

One thing to remember though is when generating a SMO from the dbo.myfiles table, is that the MyK2File property will default to type Memo. You will need to change the property to a type File so you can use the content as a file.


 

0 Kudos
Reply