0

I am stuck trying to download an excel xls file from a website. The file is downloaded when a link is clicked and I need to either control where the file is saved using c# or be able to download the file in c# all together.

Here is the site - you will see the link on the top right.

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

Here is a link to a description of what looks like the method to do this kind of download, but I cannot make this work and am in great need of help. Please let me know if anyone knows how to use a webclient or basic httpwebrequest to download an xls file.

4

1 回答 1

0

您可以在任何 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();    
        }
于 2013-05-23T08:30:33.217 回答