Skip to main content
Hi,
I would like to know how to attach a word document as part of process data without using sharepoint portal. I donot have sharepoint installation on my machine.

Thanks and Regards
Prasad
To do this, you have to use use standard HTTP file uploading and insert the file into the K2 Prcess using the K2ROM.

First, on the .aspx page where you want to upload the file, you need to include an html file upload, like so:

<INPUT type="file" id="myFile" runat="server" NAME="myFile">


It is important to note that it has a runat="server" attribute as well as an id. These are needed to get access to the uploaded file from the code-behind.

What follows is a snippet of code that I am using to do exactly what you describe. Note that the actual process data field contains the uploaded file as a Base64-encoded string. So, to do anything with the file later on, it has to be decoded. K2 has facilities to handle this.

            Dim m As New System.IO.MemoryStream

Dim b As Byte
Dim i As Integer = 0
While i < myFile.PostedFile.InputStream.Length
b = myFile.PostedFile.InputStream.ReadByte
m.WriteByte(b)
i += 1
End While

Dim oByte() As Byte = m.ToArray()

Dim K2B64 As New K2Base64.K2Base64
Dim encodedFile As String = K2B64.EncodeBase64(oByte)


Dim k2 As New SourceCode.K2ROM.Connection
k2.Open("K2_SERVER")


Dim k2proc As SourceCode.K2ROM.ProcessInstance
k2proc = k2.CreateProcessInstance("PROCESSNAME")

k2proc.DataFields("Document").Value = encodedFile


This assumes the the process has a datafield called "Document" that is a String.

Shannon M. Neumann
Systems Developer I
Cooper Standard Automotive
EML: smneumann (at) cooperstandard (dot) com

Reply