K2 attachments


Badge +3

Hi all,

 

Is that anyway i can convert the physical file to xml base64 format and transfer this data to file control in k2 list view?

 

Scenario 1: Set the smartobject attachment datatype to "File"

I do not want to save the attachment as <file><content>____<content><file> in sql table which i declare my database column as nvarchar(max).

 

Scenario 2: Set the smartobject attachment datatype to "memo"

This will return the k2 temporary path of the file. My method is to copy this attachment to my predefined location.

But whenever i load the list view, when this link is passed to file control (list view), error occur ("object reference not set to an instance of an object").

 

So, my thought is to convert the physical file that i store in my predefined location to xml base64 format <file><content>___<content><file> which enable me to pass the file back to the file control (list view) successfully.

 

Is that any other ways?

 

Thanks & Regards,

Kyo.


5 replies

Badge +10

If I understand correctly, that should be possible. What you would have to do is basically, encode your actual file int base64 using .net classes (this is fairly straight forward) as that's what k2 does. Then just put that encoded string into the <content> tag and then you obviously need the filename tag at the front too.

 

 

Badge +3

Hi s0m3one,

 

Is it possible to do it in stored procedure?

As i am using sql server for k2.

 

Thanks & Regards,

Kyo.

Badge +10

I have only done this in .net (C#) so I cannot say anything. I did a qucik google and  looks like its possible.

 

Please note this in not my script:

 

declare @source varbinary(max), @encoded varchar(max), @decoded varbinary(max)
set @source = convert(varbinary(max), ‘Hello Base64′)
set @encoded = cast( as xml).value(‘xs:base64Binary(sql:variable("@source"))’, ‘varchar(max)’)
set @decoded = cast( as xml).value(‘xs:base64Binary(sql:variable("@encoded"))’, ‘varbinary(max)’)

select
convert(varchar(max), @source) as source_varchar,
@source as source_binary,
@encoded as encoded,
@decoded as decoded_binary,
convert(varchar(max), @decoded) as decoded_varchar

 

Hope that helps

Badge +3

Hi s0m3one,

 

For this one,

set @source = convert(varbinary(max), ‘Hello Base64′)

 

It sets the @source to convert text 'Hello Base64' to varbinary(max).

How am i going to set my file path to the source.

if i set @source = convert(varbinary(max), 'D:Attachmentabc.jpg'), it will only convert the file path as text to varbinary(max).


Is that anyway that i can convert my File to varbinary(max)?

Or i need to read the file content into sql then convert the content?

 

Thanks & Regards,

Kyo.

Badge +10

Hi kyo,

 

I dont think SQL support that from initial googling. AS I said I have only done this in C# so I am not really sure about sql. Is there a reason why you dont want to use c# or equivalent.

 

 

Reply