:: Home     :: Add Questions
Register   |   Login
 

How to use PKMCDO to programmatically upload a document to a folder in Visual C#

SUMMARY

This article describes how to use Microsoft Publishing and Knowledge Management Collaboration Data Objects (PKMCDO) for Microsoft Web Storage System to upload a document to a folder in the document library on a Microsoft SharePoint Portal Server workspace by using Microsoft Visual C#.

MORE INFORMATION
To use PKMCDO to upload a document to a folder in the document library on a SharePoint Portal Server workspace, follow these steps:
1. Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
2. On the File menu, point to New, and then click Project.
3. Under Project Types, select Visual C# Projects.
Note In Visual Studio 2005, click Visual C# under Project Types.
4. Under Templates, select Console Application, and then click OK.
By default, Class1.cs is created in Visual Studio .NET. Program.cs is created in Visual Studio 2005.

5. Add a reference to the Microsoft PKMCDO for Microsoft Web Storage System library. To do so, follow these steps:
a. On the Project menu, click Add Reference.
b. Click the COM tab, locate Microsoft PKMCDO for Microsoft Web Storage System Library, and then click Select.
Note In Visual Studio 2005, you do not have to click Select.
c. In the Add References dialog box, click OK.
d. If you are prompted to generate wrappers for the libraries that you selected, click Yes.
6. Repeat step 5 to add a reference to the Microsoft ActiveX Data Objects 2.6 Library.

7.
PKMCDO.KnowledgeDocument oDoc = new PKMCDO.KnowledgeDocument(); PKMCDO.KnowledgeFolder oFolder = new PKMCDO.KnowledgeFolder();
ADODB._Stream oWrkStream;
//TODO: Change the following variables to reflect your SharePoint Portal Server environment.
String sHref="http:////documents/testdoc.txt";
String sFilePath = "c:\\testdoc.txt" ;
String sAuthor = "AuthorName";
String sTitle = "TestDoc.txt";
String sDesc = "Test Description";
Object vEmpty = Missing.Value;
oWrkStream = (ADODB._Stream )oDoc.OpenStream(
vEmpty,
PKMCDO.EnumKnowledge_StreamOpenSourceType.pkmOpenStreamUnspecified,
"",
PKMCDO.ConnectModeEnum.adModeReadWrite,
"",
"");

oWrkStream.Type = ADODB.StreamTypeEnum.adTypeBinary;
oWrkStream.SetEOS();
oWrkStream.LoadFromFile(sFilePath);
oWrkStream.Flush();
oDoc.Author = sAuthor;
oDoc.Title = sTitle;
oDoc.Description = sDesc ;
oDoc.DataSource.SaveTo (
sHref,
null,
PKMCDO.ConnectModeEnum.adModeReadWrite,
PKMCDO.RecordCreateOptionsEnum.adCreateNonCollection,
PKMCDO.RecordOpenOptionsEnum.adOpenSource,
"" ,
"");
oDoc = null;
oWrkStream= null;


8.Insert the following statement after line 1 in Class1.cs: using System.Reflection;
9. Search for TODO in the code, and then modify the code for your environment.
10. Press F5 to build and to run the program.
 
11. Load your SharePoint Portal Server folder in Microsoft Internet Explorer, and then make sure that you can see the document.

How to use PKMCDO to programmatically upload a document to a folder in Visual C#

::Top Tags::
 
 
Copyright 2007, Megasolutions Ltd