小编use*_*989的帖子

从 url 下载 .xls 文件

我正在尝试从 url 下载 xls 文件:http : //www.site.com/ff/excel/file.aspx? deven =0

我正在使用此代码,但下载完成后,文件未正确下载。如何正确下载此文件?

string remoteFilename="http://www.site.com/ff/excel/file.aspx?deven=0";
string localFilename = "D:\\1\\1.xls";
Stream remoteStream = null;
Stream localStream = null;
WebResponse response = null;

try
{
    // Create a request for the specified remote file name
    WebRequest request = WebRequest.Create(remoteFilename);
    if (request != null)
    {
        // Send the request to the server and retrieve the
        // WebResponse object 
        response = request.GetResponse();
        response.ContentType = "application/vnd.ms-excel";

        if (response != null)
        {
            // Once the WebResponse object has …
Run Code Online (Sandbox Code Playgroud)

c# excel httpwebrequest httpwebresponse

1
推荐指数
1
解决办法
9594
查看次数

标签 统计

c# ×1

excel ×1

httpwebrequest ×1

httpwebresponse ×1