WIN 2003下ASP.Net網站無法使用使用者名稱+密碼串連SQL

來源:互聯網
上載者:User
asp.net|網站 在Web應用程式中,我們無法像在Windows應用程式那樣匯出報表,因為程式是在伺服器端執行的,執行匯出時,其結果也是在伺服器端,那應該如何才能實現完整的用戶端匯出呢?其實這個也不難,方法是:把報表指定匯出到某個網站上事先建立好的報表暫存檔案,然後利用response.redirect()指令,將瀏覽器網址指向該報表位置,這樣使用者的瀏覽器就會嘗試下載剛匯出的檔案,檔案就會被下載到用戶端,從而實現我們需要的效果。 部分代碼如下:
  
  public string ExportReport()
  {
   ExportOptions creo = new ExportOptions();
   DiskFileDestinationOptions crdo = new DiskFileDestinationOptions();
   string FileName = Request.PhysicalApplicationPath + "ExportFile\Exap.xls";
  
   //設定匯出選項
   creo = Myrpt.ExportOptions;
   creo.ExportFormatType = ExportFormatType.Excel;
   creo.ExportDestinationType = ExportDestinationType.DiskFile;
  
   //設定磁碟檔案選項
   crdo.DiskFileName = FileName;
   creo.DestinationOptions = crdo;
  
   //匯出報表
   MyRpt.Export();
   return FileName;
  }
  
  private void buttonExport_Click(object sender, System.EventArgs e)
  {
   string FileName = ExportReport();
   Response.Redirect(Replace(FileName,Request.PhysicalApplicationPath + "ExportFile\",""));
  } 
   
   
要注意的是:當在web中進行匯出時,需要對匯出目錄具有建立檔案的許可權,如果許可權不足,將會出現“拒絕訪問報表檔案……”的錯誤。 讓ASPNET使用者(安裝.NET Framework時自動產生的系統使用者)在匯出目錄文具有“寫入”許可權即可。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.