從Internet上抓取指定URL的源碼的方案(C#)(3)_.Net教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!

      推薦:ASP.NET對(duì)IIS中的虛擬目錄進(jìn)行操作
      //假如虛擬目錄名為"Webtest",先在項(xiàng)目中引用 //System.DirectoryServices.dll,再 using System.DirectoryServices; protected System.DirectoryServices.DirectoryEntry di

      /// <summary>
      /// 輸出文件路徑
      /// </summary>
      public string OutFilePath
      {
      get{return outFilePath;}
      set{outFilePath=value;}
      }
      /// <summary>
      /// 返回的字符串
      /// </summary>
      public string OutString
      {
      get{return outString;}

      }
      /// <summary>
      /// 返回提示信息
      /// </summary>
      public string NoteMessage
      {
      get{return noteMessage;}

      }

      #endregion

      #region 構(gòu)造函數(shù)
      public GetPageCode()
      {
      }
      #endregion

      #region 公共方法
      /// <summary>
      /// 讀取指定URL地址,存到指定文件中
      /// </summary>
      public void GetSource()
      {
      WebRequest request = WebRequest.Create(this.url);
      //使用代理服務(wù)器的處理
      if(this.proxyState==1)
      {
      //默認(rèn)讀取80端口的數(shù)據(jù)
      if(this.proxyPort==null)
      this.ProxyPort="80";

      WebProxy myProxy=new WebProxy();
      myProxy = (WebProxy)request.Proxy;
      myProxy.Address = new Uri(this.ProxyAddress ":" this.ProxyPort);
      myProxy.Credentials = new NetworkCredential(this.proxyAccount, this.proxyPassword, this.ProxyDomain);
      request.Proxy = myProxy;
      }
      try

      {
      //請求服務(wù)
      WebResponse response = request.GetResponse();
      //返回信息
      Stream resStream = response.GetResponseStream();
      StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
      string tempCode= sr.ReadToEnd();
      resStream.Close();
      sr.Close();

      //如果輸出文件路徑為空,便將得到的內(nèi)容賦給OutString屬性
      if(this.outFilePath==null)
      {
      this.outString=tempCode;
      }
      else
      {

      FileInfo fi = new FileInfo(this.outFilePath);
      //如果存在文件則先干掉
      if(fi.Exists)
      fi.Delete();

      StreamWriter sw = new StreamWriter(this.outFilePath,true,Encoding.Default);
      sw.Write(tempCode);
      sw.Flush();
      sw.Close();
      }
      }
      catch
      {
      this.noteMessage="出錯(cuò)了,請檢查網(wǎng)絡(luò)是否連通;";
      }


      }
      #endregion
      }
      }

      分享:ASP.NET中數(shù)據(jù)庫的操作初步----增加、刪除、修改
      注意:本文暫時(shí)不講解數(shù)據(jù)庫的數(shù)據(jù)調(diào)出和顯示,因?yàn)樗婕暗臇|西比較多,所以我們將另外詳細(xì)講解。本文主要要講的是數(shù)據(jù)庫的增加、刪除、修改。 一、定義OleDbCommand類型變量:MyCommand

      共3頁上一頁123下一頁
      來源:模板無憂//所屬分類:.Net教程/更新時(shí)間:2008-08-22
      相關(guān).Net教程