C# 如何从其他Sharepoint域下载文件

C# 如何从其他Sharepoint域下载文件,c#,sharepoint-2010,C#,Sharepoint 2010,我需要下载存储在SharePoint服务器中的文件,该服务器与用户位于不同的域中。我找到了下面的代码,它看起来和我需要的完全一样 using (FileInformation ffl = Microsoft.SharePoint.Client.File.OpenBinaryDirect(_clientCtx, serverFilePath)) { using (Stream destFile = System.IO.File.OpenWrite(completeDestinationPa

我需要下载存储在SharePoint服务器中的文件,该服务器与用户位于不同的域中。我找到了下面的代码,它看起来和我需要的完全一样

using (FileInformation ffl = Microsoft.SharePoint.Client.File.OpenBinaryDirect(_clientCtx, serverFilePath))
{
    using (Stream destFile = System.IO.File.OpenWrite(completeDestinationPath))
    {
        byte[] buffer = new byte[8 * 1024];
        int len;
        while ((len = ffl.Stream.Read(buffer, 0, buffer.Length)) > 0)
        {
            destFile.Write(buffer, 0, len);
        }
    }
}

我的问题是,我不知道如何提供允许访问SharePoint服务器的用户名和密码,以便我可以下载文件。

您的代码将无法工作,因为SharePoint服务器对象模型不会跨越服务器场的边界(实际验证)

我相信您可以使用经典的http下载来处理此场景,而不知道任何sharepoint产品:

var url = "http://otherserver/documents/mydocument.doc";
var wc = new WebClient();
wc.UseDefaultCredentials = true; // May be replaced by explicit credential
wc.DownloadFile(url, @"c:\somewhere\mydocument.doc");