簡體   English   中英

從ASPX網頁下載和Excel文件

[英]Download and Excel file from an aspx webpage

我被困試圖從網站下載Excel XLS文件。 單擊鏈接后將下載文件,我需要控制使用c#將文件保存在何處,或者能夠一起使用c#下載文件。

這是網站-您會在右上方看到鏈接。

http://reo.wellsfargo.com/WBREOHome.aspx?&srchState=AK&srchCity=&srchCounty=&srchZip=&srchPriceLower=0&srchPriceUpper=9999999&srchPropertyType=&srchBeds=0&srchBaths=0&srchStatus=

這里是對這種下載方法的描述的鏈接,但是我無法完成這項工作,因此非常需要幫助。 如果有人知道如何使用網絡客戶端或基本的httpwebrequest下載xls文件,請告訴我。

您可以在任何ASP.NET LinkBut​​ton的onclick上調用此方法。 可以設置要下載的excel文件的路徑。 進行適合您的更改。

protected void download(object sender, EventArgs e)
        {
            string fname = "Excel_Sheet_Format.xlsx";
            string path = "C:/Users/dell/Desktop/Excel_Sheet_Format.xlsx";
            string name = Path.GetFileName(path);
            string ext = Path.GetExtension(path);
            Response.AppendHeader("content-disposition","attachment; filename=" + name);
            Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            Response.WriteFile(path);
            Response.End();    
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM