下面的C#总是失败
1
未知
对象引用未设置为对象的实例
有人知道我错过了什么吗?
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);
}
答案 0 :(得分:1)
如果您将使用IP地址(http://192.168.11.253)服务器名称(http://..。),则此Web服务运行良好。
答案 1 :(得分:0)
如果不了解您的具体错误,我也会抓住稻草。您的destinationUrl
似乎是一条不完整的路径。您通常需要指定站点或网站集的整个URL。因此,我希望您的destinationUrl
类似http://192.168.11.253/[SiteName]/Shared Documents/28200.xls
而不是http://192.168.11.253/Shared Documents/28200.xls"
。