Microsoft Knowledge Base Email Alertz

(312541) - Describes how to use PKMCDO for Web Storage System to upload a document to a folder in the document library on a SharePoint Portal Server workspace by using Visual C# .NET.

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 312541 - Last Review: November 29, 2007 - Revision: 3.4

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

This article was previously published under Q312541
Caution ADO and ADO MD have not been fully tested in a Microsoft .NET Framework environment. They may cause intermittent issues, especially in service-based applications or in multithreaded applications. The techniques that are discussed in this article should only be used as a temporary measure during migration to ADO.NET. You should only use these techniques after you have conducted complete testing to make sure that there are no compatibility issues. Any issues that are caused by using ADO or ADO MD in this manner are unsupported. For more information, see the following article in the Microsoft Knowledge Base:
840667   (http://kbalertz.com/Feedback.aspx?kbNumber=840667/ ) You receive unexpected errors when using ADO and ADO MD in a .NET Framework application

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:
    1. On the Project menu, click Add Reference.
    2. 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.
    3. In the Add References dialog box, click OK.
    4. 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. Insert the following code in the existing class where you see the comment that says "TODO: Add code to start application here:"
    // TODO: Add code to start application here.
    
    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://<ServerName>/<WorkspaceName>/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.

REFERENCES

For more information, see the SharePoint Portal Server Software Development Kit (SDK).

APPLIES TO
  • Microsoft Visual C# 2005 Express Edition
  • Microsoft Visual C# .NET 2003 Standard Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft SharePoint Portal Server 2001
Keywords: 
kbhowto kbmsg KB312541
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Vinod Madanagopal - vinodmadanagopal NOSPAM-AT-NOSPAM yahoo.co.in Report As Irrelevant  
Written: 2/24/2006 2:23 AM
Hi, When i execute this code i experience an exception. An unhandled exception of type 'System.ArugumentException' occured in docadd.exe Additional Information : The parameter is incorrect I have given the namespace name as docadd. Pls help me on this. Vinod