webservice CopyIntoItems is not working to upload file to sharepoint
- by Joeri
The following piece of C# is always failing with
1
Unknown
Object reference not set to an instance of an object
Anybody some idea what i am missing?
try
{
//Copy WebService Settings
String strUserName = "abc";
String strPassword = "abc";
String strDomain = "SVR03";
String FileName = "Filename.xls";
WebReference.Copy copyService = new WebReference.Copy();
copyService.Url = "http://192.168.11.253/_vti_bin/copy.asmx";
copyService.Credentials = new NetworkCredential
(strUserName,
strPassword,
strDomain);
// Filestream of attachment
FileStream MyFile = new FileStream(@"C:\temp\28200.xls", FileMode.Open, FileAccess.Read);
// Read the attachment in to a variable
byte[] Contents = new byte[MyFile.Length];
MyFile.Read(Contents, 0, (int)MyFile.Length);
MyFile.Close();
//Change file name if not exist then create new one
String[] destinationUrl = { "http://192.168.11.253/Shared Documents/28200.xls" };
// Setup some SharePoint metadata fields
WebReference.FieldInformation fieldInfo = new WebReference.FieldInformation();
WebReference.FieldInformation[] ListFields = { fieldInfo };
//Copy the document from Local to SharePoint
WebReference.CopyResult[] result;
uint NewListId = copyService.CopyIntoItems
(FileName,
destinationUrl,
ListFields, Contents, out result);
if (result.Length < 1)
Console.WriteLine("Unable to create a document library item");
else
{
Console.WriteLine( result.Length );
Console.WriteLine( result[0].ErrorCode );
Console.WriteLine( result[0].ErrorMessage );
Console.WriteLine( result[0].DestinationUrl);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: {0}", ex.Message);
}