以下的C#片始终与web服务CopyIntoItems不工作上传文件到SharePoint
未知
对象引用不设置为一个对象的一个实例失败
有人知道我错过了什么吗?
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);
}
你应该调试一些。哪个对象变为空? – 2012-01-09 18:19:02
仅当已经有一个名为“想要在服务器上上传的文档”的文档时,才会出现此行为? – Harry 2012-04-11 09:09:40