Programmatically create a K2 compatible file


Badge +7

Hi Guys,

 

I am devloping a process that involves a hardcopy endpoint. I'm using NovacodeDocX in a custom service broker, The smartobject takes values from a smartForm and creates memory stream which is stored in a database, an additinal smartobject is used to display the files using a list method.

 

The issue I am having is one of formattting, if I write the memery stream as a blob to the databse there is no issue in .net land however, K2 seems to wrap the blob in some XML when you use the smart form file attachment control on a correctly configured smartobject.

 

Obviusly I need to accompish this programmmatically when writting to the database from my custom class as at the moment the blob is not recognised by K2.

 

When inspecting the database you can see the correct verison has <file><name><contents> tags. I think the content tags contain the actual blob. 

 

Is there a K2 object in the SDK I have to cast or write to in order for this to work?

 

Or do I have to create the wrapper on the fly?


2 replies

Userlevel 1
Badge +8

You sir have encountered the pesky and underdocumented, File Property.

 

When reading your blob back you will have to define a new FileProperty. Assign the FileName and Content (?) values. The content value will need to be base 64 encoded. This file property you can then return the XML structure to your Property defined on the serviceobject that will be attributed at type SoType.File but the actual C# public property will be string.

 

Snippet

FileProperty fp = new FileProperty();
fp.FileName = "yourFileName.txt";
fp.Content = "This is base64 encoded binary data.";
fp.Value; //Set me to your public proptery.

The attribute declaration if you are doing a static broker will look like:

Snippet

[Attributes.Property("MyFile",SoType.File,"My File","This is a file object property.")]
public string MyFile { getset; }

 This should get you going.

 

Hope this helps.

 

S.

Badge +7

Thank for the advice, I have found the documentation that covers uploading a fikle to k2 and rather than mess around with a custom sql statement I found interacting  with he smartobject was just as easy!

 

Here is the documentation:

 

http://help.k2.com/onlinehelp/k2blackpearl/devref/current/default.htm#working_with_smartobjects_updload_file.html

 

I wrote a small console app that leverages the code above and found that it does enter values into the database in a format that I can then put into a view. Now I still have erros when I try to open the document but at least the encoding looks right in the db.

 

 

 

 

Reply