|
The PKMCDO Object ModelAn extensive discussion of the PKMCDO Object Model is beyond the scope of this book. Instead, I’ll cover some of the most important objects in the PKMCDO Object Model to give you a basic understanding of what PKMCDO can do. The PKMCDO Object Model allows you to accomplish programmatically many of the tasks that you would perform in the Web folders user interface. At the top of the PKMCDO Object Model is the KnowledgeServer object. To help you understand the dependencies in the PKMCDO Object Model, the EnumerateWorkspaces procedure displays workspaces, folders, and documents in the Debug window. Here is the code for the procedure:
Sub EnumerateWorkspaces()
Dim oServer As New PKMCDO.KnowledgeServer
Dim oWS As New PKMCDO.KnowledgeWorkspace
Dim oFolder As New PKMCDO.KnowledgeFolder
Dim oCategory As New PKMCDO.KnowledgeCategoryFolder
Dim oDocument As New PKMCDO.KnowledgeDocument
Dim oVersion As New PKMCDO.KnowledgeVersion
Dim oContentClass As New PKMCDO.KnowledgeContentClass
Dim rsWorkspaces, rsFolders, rsCategories As ADODB.Recordset
Dim rsDocuments, rsVersions As ADODB.Recordset
Dim strServerURL, strWorkspaceURL As String
Dim strFolderURL, strDocumentURL As String
On Error Resume Next
strServerURL = InputBox _
("Enter the URL for SharePoint Portal Server (http://<servername>):", _
"Enumerate Workspaces")
If strServerURL = "" Then
Exit Sub
End If
If Right(strServerURL, 1) = "/" Then
strServerURL = Left(strServerURL, Len(strServerURL) - 1)
End If
oServer.DataSource.Open strServerURL & "/Public/Workspaces"
Debug.Print "Server Creation Date: " & oServer.CreationDate & " GMT"
Debug.Print "SMTP Server: " & oServer.SMTPServerName
Debug.Print "Workspaces on : " & strServerURL
Set rsWorkspaces = oServer.Workspaces
While Not rsWorkspaces.EOF
strWorkspaceURL = rsWorkspaces.Fields(PKMCDO.cdostrURI_HREF)
strWorkspaceURL = strServerURL & "/" _
& Right(strWorkspaceURL, _
Len(strWorkspaceURL) - InStrRev(strWorkspaceURL, "/"))
Debug.Print rsWorkspaces.Fields(PKMCDO.cdostrURI_DisplayName)
Debug.Print Chr(9) & "(" & _
rsWorkspaces.Fields(PKMCDO.cdostrURI_Description) & ")"
Debug.Print Chr(9) & strWorkspaceURL
‘Open the workspace
oWS.DataSource.Open strWorkspaceURL
Set rsFolders = oWS.Subfolders
Debug.Print Chr(9) & Chr(9) & "Folders:"
While Not rsFolders.EOF
strFolderURL = rsFolders.Fields("DAV:href")
Debug.Print Chr(9) & Chr(9) _
& rsFolders.Fields(PKMCDO.cdostrURI_DisplayName)
Debug.Print Chr(9) & Chr(9) & strFolderURL
If rsFolders.Fields("DAV:contentclass") = _
"urn:content-classes:rootcategoryfolder" Then
oCategory.DataSource.Open strFolderURL
Debug.Print Chr(9) & Chr(9); "Category: " & oCategory.DisplayName
Set rsCategories = oCategory.Subfolders
While Not rsCategories.EOF
Debug.Print Chr(9) & Chr(9) & Chr(9) _
& rsCategories.Fields(PKMCDO.cdostrURI_DisplayName)
Debug.Print Chr(9) & Chr(9) & Chr(9) _
& rsCategories.Fields("DAV:href")
rsCategories.MoveNext
Wend
End If
oFolder.DataSource.Open strFolderURL
Debug.Print Chr(9) & Chr(9) & Chr(9) & "Items:"
Set rsDocuments = oFolder.Items
While Not rsDocuments.EOF
strDocumentURL = rsDocuments.Fields("DAV:href")
Debug.Print Chr(9) & Chr(9) & Chr(9) _
& rsDocuments.Fields(PKMCDO.cdostrURI_DisplayName)
Debug.Print Chr(9) & Chr(9) & Chr(9) _
& strDocumentURL
oDocument.DataSource.Open strDocumentURL
Debug.Print Chr(9) & Chr(9) & Chr(9) & oDocument.Author
Debug.Print Chr(9) & Chr(9) & Chr(9) & oDocument.Title
Debug.Print Chr(9) & Chr(9) & Chr(9) & oDocument.ContentClass
Set oContentClass = oDocument.ContentClassObject
‘Corresponds to Document Profile Name
Debug.Print Chr(9) & Chr(9) & Chr(9) & oContentClass.Title
Set rsVersions = oVersion.VersionHistory(strDocumentURL)
While Not rsVersions.EOF
Debug.Print Chr(9) & Chr(9) & Chr(9) & Chr(9) & _
"Checked Out: " & rsVersions.Fields _
("urn:schemas-microsoft-com:publishing:IsCheckedOut")
Debug.Print Chr(9) & Chr(9) & Chr(9) & Chr(9) & _
"Version: " & rsVersions.Fields _
("urn:schemas-microsoft-com:publishing:FriendlyVersionID")
rsVersions.MoveNext
Wend
rsDocuments.MoveNext
Wend
rsFolders.MoveNext
Wend
rsWorkspaces.MoveNext
Wend
End Sub
The code for EnumerateWorkspaces and additional SharePoint Portal Server code examples using MSDAIPP and PKMCDO can be found in the basPKMCDO standard module in the VBAProject.otm that accompanies this book.
The KnowledgeServer ObjectThe KnowledgeServer object represents a SharePoint Portal Server. KnowledgeServer objects are the primary mechanism for creating and organizing workspaces. The KnowledgeServer object provides methods for creating, deleting, and enumerating KnowledgeWorkspaces. A KnowledgeServer object contains a Workspaces property that returns an ADODB Recordset object containing all the KnowledgeWorkspaces in the KnowledgeServer. You obtain a KnowledgeServer object by opening it with a SharePoint Portal Server URL. Here’s an example: oServer.DataSource.Open strServerURL & "/Public/Workspaces" Set rsWorkspaces = oServer.Workspaces The KnowledgeWorkspace ObjectThe KnowledgeWorkspace object represents a knowledge workspace which contains content-class definitions and property definitions, as well as the root Categories folder and the root Documents folder. A KnowledgeWorkspace object contains a Subfolders property that returns an ADODB Recordset object that contains all the KnowledgeFolders in the KnowledgeWorkspace. You obtain a KnowledgeWorkspace object by opening it with a workspace URL. Here’s an example: oWS.DataSource.Open strWorkspaceURL Set rsFolders = oWS.Subfolders The KnowledgeCategoryFolder ObjectThe KnowledgeCategoryFolder object represents a category folder in the SharePoint Portal Server folder hierarchy. A KnowledgeCategoryFolder object is a special type of KnowledgeFolder object. KnowledgeFolder objects provide a physical container for KnowledgeDocument objects. KnowledgeCategoryFolder objects provide a logical grouping of KnowledgeDocument objects. They do not actually contain the KnowledgeDocument objects, because one KnowledgeDocument object can belong to one or more KnowledgeCategoryFolder objects. A KnowledgeCategoryFolder object contains a Subfolders property that returns an ADODB Recordset object that contains all the subcategories in the KnowledgeCategoryFolder. It also contains an Items property that returns an ADODB Recordset object containing all the items that have been assigned to the category represented by the KnowledgeCategoryFolder object. Here’s an example: oCategory.DataSource.Open strFolderURL Set rsCategories = oCategory.Subfolders The KnowledgeFolder ObjectThe KnowledgeFolder object represents a knowledge folder. All documents are stored in a set of hierarchical folders that operate similarly to file-system directories. Some folders can contain items in addition to documents, such as property definitions and dictionaries. A KnowledgeFolder object contains an Items property that returns an ADODB Recordset object containing all the items in the KnowledgeFolder. Here’s an example: oFolder.DataSource.Open strFolderURL Set rsDocuments = oFolder.Items All Recordsets returned by PKMCDO have a RecordCount property equal to -1. Instead of relying on the RecordCount property, you should use a While or Do Until loop to check for the EOF of the Recordset and use the MoveNext method within the loop.
The KnowledgeDocument ObjectThe KnowledgeDocument object represents a document that is contained in the store on a SharePoint Portal Server. You can access many of the default document properties such as Author, Title, Description, Keywords, and Categories directly through the KnowledgeDocument object.
oDocument.DataSource.Open rsDocuments.Fields("DAV:href")
Debug.Print Chr(9) & Chr(9) & Chr(9) & oDocument.Author
Debug.Print Chr(9) & Chr(9) & Chr(9) & oDocument.Title
Debug.Print Chr(9) & Chr(9) & Chr(9) & oDocument.ContentClass
The KnowledgeContentClass ObjectThe KnowledgeContentClass object represents a SharePoint Portal Server Document Profile. Each document in SharePoint Portal Server is associated with the KnowledgeContentClass object that defines the object through its ContentClassObject property. Set oContentClass = oDocument.ContentClassObject ‘Corresponds to document profile name Debug.Print Chr(9) & Chr(9) & Chr(9) & oContentClass.Title The KnowledgeVersion ObjectThe KnowledgeVersion object provides methods such as Approve, CheckIn, CheckOut, Publish, and VersionHistory for managing document versions. A KnowledgeVersion object is not a dependent object of a KnowledgeDocument object. You can obtain the versions for a KnowledgeDocument object by calling the VersionHistory method of the KnowledgeVersion object and supplying a URL to the KnowledgeDocument object. The VersionHistory method returns a Recordset object that contains all the versions of the KnowledgeDocument object specified in the URL.
Set rsVersions = oVersion.VersionHistory(strDocumentURL)
While Not rsVersions.EOF
Debug.Print Chr(9) & Chr(9) & Chr(9) & Chr(9) & _
"Checked Out: " & rsVersions.Fields _
("urn:schemas-microsoft-com:publishing:IsCheckedOut")
Debug.Print Chr(9) & Chr(9) & Chr(9) & Chr(9) & _
"Version: " & rsVersions.Fields _
("urn:schemas-microsoft-com:publishing:FriendlyVersionID")
rsVersions.MoveNext
Wend
The object libraries for Word 2002, Excel 2002, and PowerPoint 2002 support SharePoint Portal Server document management with properties and methods that are native to their respective object models. Depending upon the context, you might not have to use PKMCDO to get the job done. However, the Outlook 2002 Object Model does not offer any methods or properties that pertain to document management on SharePoint Portal Server.
|