I am new to SharePoint. I am trying to upload a document to SharePoint from my hard drive. I get "Parameter is incorrect" error on SaveTo method. Please help! Below is the code I am using -
using System;
using System.Reflection;
namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// 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=" Documents/TestDoc.txt";
String sFilePath = "c:\\TestDoc.txt" ;
String sAuthor = "AuthorName";
String sTitle = "TestDocument";
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.adModeWrite,
PKMCDO.RecordCreateOptionsEnum.adCreateNonCollection,
PKMCDO.RecordOpenOptionsEnum.adOpenSource,
"" ,
"");
oDoc = null;
oWrkStream= null;
//
}
}
}
using System;
using System.Reflection;
namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// 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=" Documents/TestDoc.txt";
String sFilePath = "c:\\TestDoc.txt" ;
String sAuthor = "AuthorName";
String sTitle = "TestDocument";
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.adModeWrite,
PKMCDO.RecordCreateOptionsEnum.adCreateNonCollection,
PKMCDO.RecordOpenOptionsEnum.adOpenSource,
"" ,
"");
oDoc = null;
oWrkStream= null;
//
}
}
}