错误:操作已超时

时间:2015-03-31 14:33:15

标签: c# asp.net filestream

我正在尝试将Excel文件保存到共享位置。

protected void Button1_Click(object sender, EventArgs e)
{
   string conn =      ConfigurationManager.ConnectionStrings["NameConn"].ConnectionString;
            DataTable dt = new DataTable();
using (SqlConnection odbcCon = new SqlConnection(conn))
            {
                odbcCon.Open();
                SqlCommand cmd = new SqlCommand("GetValues", odbcCon);
                cmd.Parameters.AddWithValue("@Name", "abc");
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                adapter.Fill(dt);

            }
    string destFilename = HttpContext.Current.Server.MapPath("~/A.xls");
    System.Net.WebClient client = new System.Net.WebClient();
    client.DownloadFile(path, destFilename);
}

Web.config

<httpRuntime targetFramework="4.5" executionTimeout="10000" maxRequestLength="2147483647" shutdownTimeout="360" />

我收到了这个错误:

  
      
  • 操作已超时。
  •   

你能告诉我哪里出错了。

1 个答案:

答案 0 :(得分:0)

File.Create Method返回FileStream,而WebClient.DownloadFile Method需要两个string参数,一个用于The URI from which to download data.,另一个用于The name of the local file that is to receive the data.

所以你应该这样做:

//you may also need to check if the file is exist. 
string destFilename = @"\\Networkserver path\websites\destexcel.xlsx";

System.Net.WebClient client = new System.Net.WebClient();
client.DownloadFile(path, destFilename);