Code Automatically Generated by K2 for InfoPath Activity

  • 3 October 2006
  • 2 replies
  • 2 views

Badge +4
Questions about K2 InfoPath Activity:

See the code snippet generated by k2 workflow.
In it, there are lines:
Dim spsList As New K2SPSList()
spsList.UploadDocumentFromUrl(strWorkSpaceName, FileURL, oByte, True, errMess)

1. What is K2SPSList? What DLL is it from?

2. What does spsList.uploadDocumentFromUrl() do?
-Upload the XML string from K2 workflow to a SharePoint form library?
-It looks like the uploadDocumentFromUrl() will attach headers to the XML string:
the header looks like-<?xml version="1.0"?>
<?mso-infoPathSolution solutionVersion="1.0.1.71" PIVersion="1.0.0.0" href="http://soandso/doclib/Forms/template.xsn"
name="urn:schemas-microsoft-com:office:infopath:template:soandso_1B9F6425-7E10-457b-BDB6-FC6B4F304D6B"
productVersion="11.0.6565" ?>
-Where is the information from such as
solutionVersion="1.0.1.71"
PIVersion="1.0.0.0" href="http://soandso/doclib/Forms/template.xsn"

-Are these from SharePoint library?

-------------------------------------------------------------------------------------
The following is the code snippet generated by K2 workflow for InfoPath activity:

Sub Main(K2 as SourceCode.KO.ClientEventContext)
'Create the ActivityInstance of the InfoPath Document - Do not Remove this Code - InfoPath Web service relies on this data
K2.ActivityInstanceDestination.XmlFields("K2InfoPathSchema").Value = K2.ProcessInstance.XmlFields("K2InfoPathSchema").Value
SendDocURL(K2)
End Sub
Public Function SendDocURL(K2 as SourceCode.KO.ClientEventContext) As String
Dim K2SPUtil As New SourceCode.K2SPUtilities.SPSUtilities()
Dim strXMLString As String
Dim TempPath As String = ""
Dim FileURL As String
Dim FileName As String = ""
Dim i,j As Integer
Dim strView As String = "Review"
Dim strProcessName As String = K2.ProcessInstance.Process.Name
Dim strActivityName As String = K2.ActivityInstanceDestination.ActivityInstance.Activity.Name
Dim oXMLFields As SourceCode.KO.XmlFields = K2.ProcessInstance.XmlFields
Dim sDestUserFQN As String = K2.ActivityInstanceDestination.User.FQN
Dim sDestUserManagerFQN As String = K2.ActivityInstanceDestination.User.Manager
If FileName = "" Then
FileName = K2.Event.Name & "." & K2.SerialNumber.Replace(",","_") & ".xml"
Else
If Right(FileName,4).ToLower <> ".xml" Then
FileName = FileName & ".xml"
End If
End If
For i = 0 To oXMLFields.Count - 1
If oXMLFields.Item(i).Name = "K2InfoPathSchema" Then
If(IsNothing(K2.ProcessInstance.XmlFields.Item(i).Value))OrElse(K2.ProcessInstance.XmlFields.Item(i).Value.ToString().Trim = "") then
If K2.ProcessInstance.DataFields("K2DisableSubmitButton").Value = True Then
strXMLString = K2SPUtil.UpdateDocumentWithView(K2.ProcessInstance.XmlFields.Item(i).MetaData, strView,K2.SerialNumber, K2.ProcessInstance.ID,"",sDestUserFQN & "," & sDestUserManagerFQN,K2.ProcessInstance.DataFields("K2ShowViewFlowLink").Value,K2.ProcessInstance.DataFields("K2UseCachedViewFlowData").Value)
Else
strXMLString = K2SPUtil.UpdateDocumentWithView(K2.ProcessInstance.XmlFields.Item(i).MetaData, strView,K2.SerialNumber, K2.ProcessInstance.ID,"","",K2.ProcessInstance.DataFields("K2ShowViewFlowLink").Value,K2.ProcessInstance.DataFields("K2UseCachedViewFlowData").Value)
End If
Else
If K2.ProcessInstance.DataFields("K2DisableSubmitButton").Value = True Then
strXMLString = K2SPUtil.UpdateDocumentWithView(K2.ProcessInstance.XmlFields.Item(i).Value, strView,K2.SerialNumber, K2.ProcessInstance.ID,"",sDestUserFQN & "," & sDestUserManagerFQN,K2.ProcessInstance.DataFields("K2ShowViewFlowLink").Value,K2.ProcessInstance.DataFields("K2UseCachedViewFlowData").Value)
Else
strXMLString = K2SPUtil.UpdateDocumentWithView(K2.ProcessInstance.XmlFields.Item(i).Value, strView,K2.SerialNumber, K2.ProcessInstance.ID,"","",K2.ProcessInstance.DataFields("K2ShowViewFlowLink").Value,K2.ProcessInstance.DataFields("K2UseCachedViewFlowData").Value)
End If
End If
For j = 0 To K2.ActivityInstanceDestination.XmlFields.Count
If K2.ActivityInstanceDestination.XmlFields.Item(j).Name = "K2InfoPathSchema" Then
K2.ActivityInstanceDestination.XmlFields.Item(j).Value = strXMLString
exit for
End If
Next
Exit For
End If
Next
'Begin SharePoint Integration********
Dim spsList As New K2SPSList()
Dim strWorkSpaceURL As String
Dim strDocLib As String
Dim strWorkSpaceName As String = ""
Dim strServerURL as string
Dim strPartServerURL as string
Dim oByte() As Byte
If strXMLString.Trim.Length = 0 Then
Exit Function
Else
'Read into byte array
Dim oTextEncoder As New System.Text.UTF8Encoding
oByte = oTextEncoder.GetBytes(strXMLString)
oTextEncoder = Nothing
End If
strServerURL = K2.ProcessInstance.DataFields("K2SharePointURL").MetaData & "/_vti_bin/K2SpsList.asmx"
strPartServerURL = K2.ProcessInstance.DataFields("K2SharePointURL").MetaData
If strServerURL.Trim <> "" then
spsList.URL = strServerURL
End If
spsList.Credentials = K2SPUtil.GetCredentials(strPartServerURL)
Try
If K2.ProcessInstance.DataFields.Item("K2CreateNewWS").Value = True then
If K2.ProcessInstance.DataFields.Item("K2DWSName").MetaData.Trim.Length > 0 then
strWorkSpaceName = K2.ProcessInstance.DataFields.Item("K2DWSName").MetaData & "/" & K2.ProcessInstance.DataFields.Item("K2DWSName").Value
Else
strWorkSpaceName = K2.ProcessInstance.DataFields.Item("K2DWSName").Value
End If
Else
strWorkSpaceName = K2.ProcessInstance.DataFields.Item("K2DWSName").Value
End If
strWorkSpaceURL = K2.ProcessInstance.DataFields("K2DWSPath").Value
Catch
strWorkSpaceName = ""
strWorkSpaceURL = ""
End Try
strDocLib = K2.ActivityInstanceDestination.DataFields.Item("DocFolder").Value
If right(strWorkSpaceURL,1) <> "/" Then
strWorkSpaceURL += "/"
End If
If right(strDocLib ,1) <> "/" Then
strDocLib += "/"
End If
Dim ret As Boolean, errMess As String
FileURL = strWorkSpaceURL + strDocLib + FileName


If spsList.UploadDocumentFromUrl(strWorkSpaceName, FileURL, oByte, True, errMess) then
'Update the Activity Fields for Cleanup purposes
K2.ActivityInstanceDestination.DataFields("SPFileURL").Value = FileURL
K2.ActivityInstanceDestination.DataFields("SPFileSite").Value = strWorkSpaceName
Else
Throw New System.Exception(errMess)
End If
oByte = Nothing
'End SharePoint Integration********
FileURL = System.Web.HttpUtility.UrlPathEncode(FileURL)
K2.AddWorklist("ASP",FileURL)
End Function

2 replies

Badge +5

Hopefully I can clarify here:


 So K2SPSList.dll is the webservice we use to perform the functionality we provide for our wizards to integrate with SharePoint and InfoPath, anything prefixed with k2 is a k2 dll, not a Microsoft one, another reason it resides in our bin directory.  I see it as a nice wrapper of Microsoft SharePoint and InfoPath dlls, we basically took the functionality we provide, created an API for it, and then called all the necessary SP and IP dlls from ours, it is just another layer of abstraction from their dlls.  You can also find functionality in there that we don't necessarily provide with a wizard.  For instance if you want to create a folder in a document library you can use the webservices wizard, connect to the k2spslist.dll and then call the createfolder() function, it will query the input values and return values without you having to write a line of code.  K2spslist.dll maps easier to our dialogs then Microsoft's dlls.  In the case of UploadFilefromURL is taking a file from a SP location and uploading it vs. taking it from binary data within a k2 process.  Usually a glance over the help file for the wizard can bring a lot of clarity to the API as the options usually match the API names pretty close :).  Good luck.


~Cherish


 

Badge +1

Hi Cherish,


I'm really looking for a solution on how to create folders in a SP-list from K2. I just can't find the help-documentation you mentioned, and I'm not sure where to start looking. Any clues?


 (and why isn't such an important function implemented in the SP-list wizards in Blackpearl? =P )

Reply