2012-02-13 7 views
0

へのHTMLパス...保存Webクライアントを使用するために自分のコードを編集したファイル

string hhtmlurl = /Thumbnail.aspx?productID=23&Firstname=jimmy&lastnight=smith; 

string strFileName = string.Format("{0}_{1}", hfUserID.Value, Request.QueryString["pid"].ToString() + documentID.ToString()); 
WebClient client = new WebClient(); 
client.DownloadFile("http://www.url.ca/" + hhtmlurl.Value + "card=1", strFileName); 
+0

どのように機能しませんか?それは何をするためのものか? – svick

答えて

0

は、この方法を試してみてください:

+0

このコードでは、ファイルを保存して自分のファイル名を入れますか? – user979331

+0

その部分はここでは使用できません。 l私の上記のメソッドとそれは文字列内の全体のWebページのコンテンツを返します。次に、streamwriter(http://msdn.microsoft.com/en-us/library/6ka1wd3w.aspx)を使用して、この文字列を別のファイルに書き込む –

+0

Worked !!!すごい男! – user979331

0

WebClient.DownloadFileまだdoesntの仕事は、おそらく容易になるだろう。

WebClient client = new WebClient(); 
client.Downloadfile("http://www.url.ca/" + hhtmlurl + "card=1", strFileName); 
0

代わりのFileStreamを、楽しく簡単なDownloadFile()方法を提供していますWebClientクラスを使用します。これにより、HTMLコンテンツ全体の文字列リターンが得られます。任意のファイルでこの文字列を書きます

public string GetHtmlPageContent(string url) 
    { 
     HttpWebResponse siteResponse = null; 
     HttpWebRequest siteRequest = null; 
     string content= string.Empty; 

     try 
     { 
      Uri uri = new Uri(url); 
      siteRequest = (HttpWebRequest)HttpWebRequest.Create(url); 
      siteResponse = (HttpWebResponse)siteRequest.GetResponse(); 

      content = GetResponseText(siteResponse); 
     } 
     catch (WebException we) 
     { 
      // Log error 
     } 
     catch (Exception e2) 
     { 
      // Log error 
     } 

     return content; 
    } 

     public string GetResponseText(HttpWebResponse response) 
    { 
     string responseText = string.Empty; 

     if (response == null) 
      return string.Empty; 

     try 
     { 
      StreamReader responseReader = new StreamReader(response.GetResponseStream()); 
      responseText = responseReader.ReadToEnd(); 
      responseReader.Close(); 
     } 
     catch (Exception ex) 
     { 
      // Log error 
     } 

     return responseText; 
    } 

希望すると、これが役に立ちます。

+0

うーん...それは働いていないようだ...私は私のクライアントに気づいた。ダウンロードファイルはあなたのように緑色ではない。黒色私はSystem.netを使用しています、何か不足していますか? – user979331

+0

あなたのコードに 'using System.Net;'指示文があることを確認するか、 'System.Net.WebClient client = new System.Net.WebClient()'を明示的に呼び出してください。 –

+0

まだ何もありません:(私は – user979331