Evaluating checkout status of SharePoint documents
KB000091
PRODUCTKB000007 - Combining a SharePoint Server List Item with a K2.netT 2003 Client Event
TAGSThis document describes how to check whether a document in a SharePoint shared document library is checked out before downloading the document.
Introduction Instances may arise where an attempt to access or update documents in SharePoint fails because the documents have already been checked out by another user. The K2.net process would therefore be unable to perform an update to the documents. This condition can be handled as follows: | |
| |
ElseIf ErrorMessage.Length() = 0 Then | |
See the code sample as shown below: | |
VB .NET Code Sample
Public Sub Main(ByRef K2 As ServerEventContext) ' Set up variables Dim Temp as String, ErrorMessage As String = "" Dim Server As String Server = "http://sps.k2mega.local" If Not Server.EndsWith("/") Then Server &= "/" Dim Site As String Site = "sites/sales" If Not Site.EndsWith("/") And Site.Trim <> "" Then Site & = "/" Dim Folder As String Folder = "Shared Documents" If Not Folder.EndsWith("/") Then Folder &= "/" Dim File As String File = "test.txt" Dim LocalFolder As String LocalFolder = "C:Documents and SettingsAdministratorDesktop" Dim LocalFile As String LocalFile = "newtest.txt" Dim SpsList As New K2SPSList() ' Set Url for Web Service SpsList.Url = Server & "_vti_bin/K2SpsList.asmx" ' Set Credentials Dim SpsUtils As New SourceCode.K2SPUtilities.SPSUtilities SpsList.Credentials = SpsUtils.GetCredentials(Server) '########################################################## '# Download the document '########################################################## Dim oByte() As Byte ' Call Web Service to Download Document If Not SpsList.GetDocument(Server, Site, Folder, _ File, oByte, ErrorMessage) Then ' Error Occurred in GetDocument - Raise Error Throw New System.Exception(ErrorMessage) End If Dim K2B64 As New K2Base64.K2Base64() ' Build The file path Dim LocalFilePath As String If Not LocalFolder.EndsWith(""") Then LocalFilePath = LocalFolder & """ & LocalFile Else LocalFilePath = LocalFolder & LocalFile End If K2B64.ByteArrayToFile(oByte, LocalFilePath) '########################################################## '########################################################## '# Check out the document '########################################################## ' Call Web Service to check out Document If Not SpsList.CheckOutDocument(Site, Folder, _ File, ErrorMessage) ' Error Occurred in CheckOutDocument - Raise Error ' If the document has been checked out by somebody else, ' ErrorMessage will typically contain: ' The file "Shared Documents/test.txt" is checked out or ' locked for editing by K2MEGAadministrator. If ErrorMessage.IndexOf("The file", 0) = 0 And _ ErrorMessage.IndexOf("is checked out or locked for editing", 0) > 0 Then ' Here you can typically set a process variable which can be ' tested in the Succeeding Rule of the Activity. Console.WriteLine("The document is checked out or locked") ElseIf ErrorMessage.Length() = 0 Then ' If you want to download the document ONLY if the document ' is not checked out, put the # Download the document # code ' here. Else Throw New System.Exception(ErrorMessage) End If End If '########################################################## End Sub
|