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.
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....
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.
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 Rdbo].PStringtoK2File] @Filename nvarchar(50), @String nvarchar(MAX)ASBEGINDECLARE @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 tdbo].SMyFiles] (dText], FMyK2File],) 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.
So where does the file reside in this scenario?