Skip to main content
I am uploading multiple documents, and want to store the file details as multiple elements, e.g:


<root>
<docitems>
<doc>c: emp
ob.doc</doc>
<doc>c: emp
ob2.doc</doc>
<doc>c: emp
ob3.doc</doc>
</docitems>
</root>


In my smartform, every time I click an upload button, it creates a new <doc> element, and stores the value with K2.

At least, that is what I WANT to do, I cannot find any examples anywhere

HELP

Many thanks
You may consider using the simple approach of manipulating the structure of an XML datafield directly to achieve the objective.
For instance, if you have an XML field of the following structure that is bound to a K2DataGrid:
<K2DataGridRoot>
<Item>
<Comments></Comments>
<By></By>
<Date></Date>
</Item>
</K2DataGridRoot>

This K2DataGrid may be used to display comments from various people along the workflow. Use a server event that contains the following code at the end of each activity to update the XML by inserting a new row.

If K2.ProcessInstance.DataFields.Item("Comment").Value <> "" Then
Dim strItem As String = K2.ProcessInstance.XmlFields("ManagementComments").Value
strItem = strItem.Substring(0,strItem.IndexOf("</K2DataGridRoot>"))
strItem += "<Item><Comments>"+K2.ProcessInstance.DataFields.Item("Comment").Value + "</Comments>"
strItem += "<By>"+K2.ProcessInstance.DataFields.Item("ReviewedBy").Value + "</By>"
strItem += "<Date>"+K2.ProcessInstance.DataFields.Item("ReviewedDate").Value + "</Date></Item>"
strItem += "</K2DataGridRoot>"
K2.ProcessInstance.XmlFields("ManagementComments").Value = strItem
' clear comment field
K2.ProcessInstance.DataFields.Item("Comment").Value = ""
End if

Thanks Samuel,

I guess also you could load the field into the document model


System.Xml.XmlDocument myDocument = new System.Xml.XmlDocument();
myDocument.LoadXml(K2.ProcessInstance.XmlFields("ManagementComments").Value);
but, I like your method, and I hadn't thought about binding it to a datagrid which is excellent

Many thanks
To allow for multiple instances of an element (Comment in this case), as it is causing issues.

Am I better off storing my xml as a normal string Datafield, or is there a way to fix this to allow for multiple rows (I am gettingan xsdinfer.dll error on the page when I add a frid, due to the fact the schema does not by default allow you to configure multiple elements)

Reply