【问题标题】:consuming sharepoint 2010 web service with visual studio 2010使用 Visual Studio 2010 使用 Sharepoint 2010 Web 服务
【发布时间】:2012-04-14 02:10:29
【问题描述】:

我正在尝试通过 Visual Studio 2010 使用 SharePoint 2010 Web 服务。我想下载文档库中只有经过身份验证的用户才能访问的所有文件。我发现没有教程有效。有人可以帮帮我吗?

【问题讨论】:

    标签: c# visual-studio-2010 sharepoint-2010


    【解决方案1】:

    试试这个代码:请试试下面的函数。您需要传递 FileURL(文档的完整网址),Title(您要为下载的文件提供的传递名称。)

    (注意:此功能需要传递凭据以及您要下载的文档的完整网址。我认为这对您来说已经足够了)

    public string DownLoadfiletolocal(string FileURL, string Title)
    {
    
    //Copy.Copy is a webservice object that I consumed.
    
    Copy.Copy CopyObj = new Copy.Copy();
    CopyObj.Url = SiteURL + "/_vti_bin/copy.asmx"; // Dynamically passing SiteURL
    NetworkCredential nc2 = new NetworkCredential();
    nc2.Domain = string.Empty;
    nc2.UserName = _UserName;
    nc2.Password = _Password;
    
    
    string copySource = FileURL; //Pass full url for document.
    
    Copy.FieldInformation myFieldInfo = new Copy.FieldInformation();
    Copy.FieldInformation[] myFieldInfoArray = { myFieldInfo };
    byte[] myByteArray;
    
    // Call the web service
    uint myGetUint = CopyObj.GetItem(copySource, out myFieldInfoArray, out myByteArray);
    
    // Convert into Base64 String
    string base64String;
    base64String = Convert.ToBase64String(myByteArray, 0, myByteArray.Length);
    
    // Convert to binary array
    byte[] binaryData = Convert.FromBase64String(base64String);
    
    // Create a temporary file to write the text of the form to
    string tempFileName = Path.GetTempPath() + "\\" + Title;
    
    // Write the file to temp folder
    FileStream fs = new FileStream(tempFileName, FileMode.Create, FileAccess.ReadWrite);
    fs.Write(binaryData, 0, binaryData.Length);
    fs.Close();
    
    return tempFileName;
    
    }
    

    【讨论】:

    • 谢谢,如果我已经可以获取文档库中的文档列表,我会使用您的代码。
    • 我添加了对copy.asmx服务的服务引用,但是没有复制接口。只有 CopySoap。
    • 使用 Web 参考添加此服务未在服务参考中添加
    猜你喜欢
    • 1970-01-01
    • 2012-02-22
    • 2012-07-08
    • 1970-01-01
    • 2013-05-26
    • 1970-01-01
    • 1970-01-01
    • 2011-03-26
    • 1970-01-01
    相关资源
    最近更新 更多