Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# webservice CopyIntoItems无法将文件上载到sharepoint_C#_Sharepoint_Web Services - Fatal编程技术网

C# webservice CopyIntoItems无法将文件上载到sharepoint

C# webservice CopyIntoItems无法将文件上载到sharepoint,c#,sharepoint,web-services,C#,Sharepoint,Web Services,下面这段C#总是失败 一, 不为人知 对象引用未设置为对象的实例 有人知道我错过了什么吗 try { //Copy WebService Settings String strUserName = "abc"; String strPassword = "abc"; String strDomain = "SVR03";

下面这段C#总是失败

一,

不为人知

对象引用未设置为对象的实例

有人知道我错过了什么吗

        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);
        }
试试看
{
//复制Web服务设置
字符串strUserName=“abc”;
字符串strPassword=“abc”;
字符串strDomain=“SVR03”;
字符串FileName=“FileName.xls”;
WebReference.Copy copyService=新建WebReference.Copy();
copyService.Url=”http://192.168.11.253/_vti_bin/copy.asmx";
copyService.Credentials=新网络凭据
(strUserName,
strPassword,
结构域);
//附件文件流
FileStream MyFile=newfilestream(@“C:\temp\28200.xls”,FileMode.Open,FileAccess.Read);
//将附件读入变量
字节[]内容=新字节[MyFile.Length];
读取(Contents,0,(int)MyFile.Length);
MyFile.Close();
//更改文件名(如果不存在),然后创建新文件名
字符串[]destinationUrl={”http://192.168.11.253/Shared 文件/28200.xls“};
//设置一些SharePoint元数据字段
WebReference.FieldInformation fieldInfo=新的WebReference.FieldInformation();
WebReference.FieldInformation[]ListFields={fieldInfo};
//将文档从本地复制到SharePoint
WebReference.CopyResult[]结果;
uint NewListId=copyService.CopyIntoItems
(文件名,
目的地,
列表字段、内容、输出结果);
如果(结果长度<1)
Console.WriteLine(“无法创建文档库项”);
其他的
{
控制台写入线(结果长度);
Console.WriteLine(结果[0]。错误代码);
Console.WriteLine(结果[0].ErrorMessage);
Console.WriteLine(结果[0].DestinationUrl);
}
}
捕获(例外情况除外)
{
WriteLine(“异常:{0}”,例如Message);
}

如果您使用IP地址()服务器名称(.)此web服务运行良好。

如果您使用IP地址()服务器名称(.)此web服务运行良好。

如果您不了解您的具体错误,我也将抓住救命稻草。看起来您的
目标URL
是一条不完整的路径。通常需要指定网站或网站集的整个URL。因此,我希望您的
destinationUrl
类似于
http://192.168.11.253/[SiteName]/Shared Documents/28200.xls
而不是
http://192.168.11.253/Shared 文件/28200.xls“

如果不进一步了解您的具体错误,我也会抓住救命稻草。看起来您的
目标URL
是一条不完整的路径。通常需要指定网站或网站集的整个URL。因此,我希望您的
destinationUrl
类似于
http://192.168.11.253/[SiteName]/Shared Documents/28200.xls
而不是
http://192.168.11.253/Shared 文件/28200.xls“

您应该调试一些。哪个对象正在变为null?只有当服务器上已经有一个名为的文档(如您要上载的文档)时才会发生这种行为吗?您应该调试一些。哪个对象正在变为null?只有当服务器上已经有一个名为的文档(如您要上载的文档)时,才会发生这种行为吗?