2016-09-05 70 views
1

からファイルをダウンロードし、私はあなたがSharePointサイトからファイルをダウンロードするためにWebRequestを使用してこのタスクを達成することができ、このコードを持っていると、エラーコード500は、私は、SharePointからファイルをダウンロードしようとしているSharePointの

 static void DownloadFile(){ 
     string serverFilePath = "Here goes my URL, that open the file from any tab"; 
     var password = new SecureString(); 
     foreach (char c in Configuration.password) { 
      password.AppendChar(c); 
     } 
     // theese are the credentials and work fine because I tested in another method 
     var o365credentials = new SharePointOnlineCredentials(Configuration.userName, password); 

     var url = string.Format("{0}/{1}", Configuration.siteUrl, serverFilePath); 
     // My destination folder 
     string destPath = @"C:\publisher"; 
     var request = System.Net.HttpWebRequest.Create(url); 
     request.Credentials = o365credentials; 
     using (var sReader = new StreamReader(request.GetResponse().GetResponseStream())) { 
      using (var sWriter = new StreamWriter(destPath)) { 
       sWriter.Write(sReader.ReadToEnd()); 
      } 
     } 
    } 
+0

あなたは疑問を持っている、またはあなたが見ているのですあなたのコードを書く人は誰ですか? – lgaud

+0

もちろん、単なる質問ですが、ファイルやパラメータをダウンロードするためにどのメソッドを呼び出すかを知ることが必要です。 –

答えて

0

を投げます:あなたがClient-object-modelを使用したい場合は

public void DownloadFile(string serverFilePath, string destPath) 
{ 
    var url = string.Format("{0}/{1}", ServerURL, serverFilePath); 
    createDirectiory(Path.GetDirectoryName(destPath)); // this method creates your directory 
    var request = System.Net.HttpWebRequest.Create(url); 
    request.Credentials = System.Net.CredentialCache.DefaultCredentials; 
    using (var sReader = new StreamReader(request.GetResponse().GetResponseStream())) 
    { 
     using (var sWriter = new StreamWriter(destPath)) 
     { 
      sWriter.Write(sReader.ReadToEnd()); 
     } 
    } 
} 

あなたはそれを読んで:How to get a file using SharePoint Client Object Model with only an absolute url at hand?

+0

この点のポイントは私がC#から知っていることです。 SharePointからではないので、serverFilePathの意味を教えてください。クレデンシャル私はClienContextを意味します。私のコードを見てください。申し訳ありませんが、 –

+0

あなたのコードはClient-object-modelを使用しています。使用したい場合は、本当に有益なリンクを追加しました。代わりの方法(私の答え)はwebrequestクラスを使用することです、serverFilePathはファイルのパスであり、Credentialsはネットワークのユーザーとパスワードです。自分で作成しなければならないcreateDirectiory()メソッド - クライアントPCにパス(フォルダ)を作成するだけの方法で、ファイルはそのパスにダウンロードされます。 – jonathana

+0

今私はよく理解していますが、それは私にエラー番号500を投げます、それはsharepoingのこの事を本当にイライラさせています。 –