[英]Error : The operation has timed out
我正在尝试将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" />
我得到这个错误:
- 操作已超时。
你能告诉我哪里错了吗?
File.Create
方法返回FileStream
,而WebClient.DownloadFile
方法需要两个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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.