【问题标题】:File uploading from web application to Sharepoint server从 Web 应用程序上传文件到 Sharepoint 服务器
【发布时间】:2013-06-15 21:26:48
【问题描述】:

这是我第一次使用 Sharepoint。这是场景

  1. 我有一个独立的网络应用程序
  2. 我还有一个独立的共享点服务器。
  3. 两者都在不同的服务器上。
  4. 我需要将文件从 Web 应用程序上传到共享点

我在网上找到了2种方法,

  1. 使用 Sharepoint 提供的网络服务 (CopyIntoItems)
  2. 使用Sharepoint webservice的jQuery库

网上搜了一下,觉得jQuery部分不行(大家可以指正)。

我正在寻找一种采用用户名/密码并将 pdf 文件上传到 Sharepoint 服务器的方法。以下是我尝试上传但最终出错的 C# 代码

public bool UploadFile(string file, string destination)
    {
        bool success = false;
        CopySoapClient client = new CopySoapClient();

        if (client.ClientCredentials != null)
            client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
        
        try
        {
            client.Open();
            
            string filename = Path.GetFileName(file);
            string destinationUrl = destination + filename;
            string[] destinationUrls = { destinationUrl };

            FieldInformation i1 = new FieldInformation { DisplayName = "Title", InternalName = "Title", Type = FieldType.Text, Value = filename };
            FieldInformation[] info = { i1 };
            CopyResult[] result;
            byte[] data = File.ReadAllBytes(file);

            //uint ret = client.CopyIntoItems(filename, destinationUrls, info, data, out result);
            uint ret = client.CopyIntoItems(file, destinationUrls, info, data, out result);

            if (result != null && result.Length > 0 && result[0].ErrorCode == 0)
                success = true;
        }
        finally
        {
            if (client.State == System.ServiceModel.CommunicationState.Faulted)
                client.Abort();

            if (client.State != System.ServiceModel.CommunicationState.Closed)
                client.Close();
        }

        return success;
    }

我这样调用上面的函数

UploadFile(@"C:\temp\uploadFile.txt", "http://spf-03:300/demo/Dokumente").ToString();

我得到的错误:

错误代码:目的地无效

错误消息:必须在包含目标 URL 的同一域上调用服务方法“复制”。

【问题讨论】:

    标签: sharepoint sharepoint-2010


    【解决方案1】:

    SharePoint 2010 有第三个选项,即使用客户端对象模型。客户端对象模型是较大 Sharepoint API 的子集,但它确实涵盖了上传文档。以下是带有上传示例的博客文章。

    Upload document through client object model

    与 SharePoint 中的大多数内容一样,您需要对网站进行身份验证,因此请确定您的网站集是基于表单还是基于声明,然后您应该能够找到适合您情况的示例代码。

    【讨论】:

    • 感谢您的回复。我尝试了您的方法,现在出现以下错误。也许安全令牌网络服务不起作用?服务器无法处理该请求。 ---> 由于内部错误,客户端无法处理请求。如果您想了解有关错误的更多信息,请启用 IncludeExceptionDetailInFaults(通过 ServiceBehaviorAttribute 或 配置行为)以使客户端将异常信息发送回服务器,或根据 Microsoft 启用跟踪。 NET 框架 3.0 SDK
    【解决方案2】:

    问题的解决方法:

    问题是“安全令牌网络服务”不起作用,当我们手动运行网络服务时它给出了一些错误。

    由于内部错误,服务器无法处理请求。 有关错误的更多信息,请打开 IncludeExceptionDetailInFaults(来自 ServiceBehaviorAttribute 或从配置行为)在服务器上发送 异常信息返回给客户端,或者按照 Microsoft .NET Framework 3.0 SDK 文档并检查 服务器跟踪日志。

    上述异常是通用异常。为了查看确切的异常,我们从 web 服务的 web.config 文件中启用了远程错误查看 (link) 并看到了确切的异常。 我们找到了异常的解决方案并启动了服务。之后一切正常。

    【讨论】:

      猜你喜欢
      • 2017-06-06
      • 1970-01-01
      • 2013-11-09
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 2010-09-21
      • 1970-01-01
      相关资源
      最近更新 更多