急,在线等!web如何打开文本框中输路径的本地文件 在aspx中如何写代码,点击按钮打开指定路径的文件(在文本框中的),例如:K:\123.xls,K是网络map盘. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用file控件 <input id="File1" type="file" /> 我倒,误会了,如果要打开相应的文件,要装相应的插件,vs的com+提供了很多,对excel文件的打开网上搜索的到N多的 protected void Page_Load(object sender, EventArgs e) { try { //导出数据 string name = DateTime.Now.ToString("yyyymmddhhmmss"); string path = Server.MapPath("~/Upload/导出Excel/" + name + ".xls"); ToExcel(path); System.IO.FileInfo file = new System.IO.FileInfo(path); Response.Clear(); Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.UTF8; // 添加头信息,为"文件下载/另存为"对话框指定默认文件名 Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name)); // 添加头信息,指定文件大小,让浏览器能够显示下载进度 Response.AddHeader("Content-Length", file.Length.ToString()); // 指定返回的是一个不能被客户端读取的流,必须被下载 Response.ContentType = "application/ms-excel"; // 把文件流发送到客户端 Response.WriteFile(file.FullName); // 停止页面的执行 Response.Flush(); Response.End(); } catch (Exception ex) { ExceptionLogger.LogException("SaleReport.ButtonDummy_Click", new ZeroGlobalException(ExceptionType.UnknownError.ToString(), ex)); } } 我的这个文件并不是在IIS服务器上,是其他的路径,有没有方法直接open这个路径的文件就可以了 string path ="IPaddress"+filefullname; 必须知道IP地址或者服务器名。用"http://www.***.com"+fullname;也可以的 我写成这样,也可以打开<a href="file://K:\IT\123.xls">test</a>但是不能把txtbox中的值传给它. 三尾,我会从数据库中读取出文件路径,并存放在textbox中,然后点击一个按钮打开这个路径的文件.请给出功能代码.谢谢 代码基本已经给了 protected void Page_Load(object sender, EventArgs e) { try { //导出数据 string name = DateTime.Now.ToString("yyyymmddhhmmss"); //这里改成你文本框控件 string path = this.txtPath.Text.Trim(); ToExcel(path); System.IO.FileInfo file = new System.IO.FileInfo(path); Response.Clear(); Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.UTF8; // 添加头信息,为"文件下载/另存为"对话框指定默认文件名 Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name)); // 添加头信息,指定文件大小,让浏览器能够显示下载进度 Response.AddHeader("Content-Length", file.Length.ToString()); // 指定返回的是一个不能被客户端读取的流,必须被下载 Response.ContentType = "application/ms-excel"; // 把文件流发送到客户端 Response.WriteFile(file.FullName); // 停止页面的执行 Response.Flush(); Response.End(); } catch (Exception ex) { ExceptionLogger.LogException("SaleReport.ButtonDummy_Click", new ZeroGlobalException(ExceptionType.UnknownError.ToString(), ex)); } } 大哥,你没放到iis的发布目录下匿名用户是没有权限打开的,解决方法,在发布目录下建立固定文件夹存放文件。输入路径是剔除K:\,改为服务器路径。问题解决。 可能是我没描述清楚,我没有把文件上传到IIS,而是把文件的路径存进了数据库,每次需要看文件直接打开这个路径的文件就可以了,如果文件不存在或者没权限看这个路径不是程序控制的问题.我只想点击view按钮就可以打开文本控件内路径的文件. System.ArgumentOutOfRangeException: 索引超出范围,求教 richtextbox中拖曳问题 网页发送消息到手机 做不好就辞职 为什么记事本中的回车是一个小框,复制到vs2005中的时候就正常是个回车 log4net的一个问题? 在C#中如何操作FastReport的barCode控件来实现条形码打印-急 DATASET是否必须实例化? borderstyle问题 在C#中调用存储过程时出现下面的错误 急!怎样判断鼠标的左右键同时被按下? 新手求助!C#中GridView数据批量添加到数据库 请教C#实现Telnet Client程序的源代码
<input id="File1" type="file" />
protected void Page_Load(object sender, EventArgs e)
{
try
{
//导出数据
string name = DateTime.Now.ToString("yyyymmddhhmmss");
string path = Server.MapPath("~/Upload/导出Excel/" + name + ".xls");
ToExcel(path); System.IO.FileInfo file = new System.IO.FileInfo(path);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", file.Length.ToString()); // 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/ms-excel"; // 把文件流发送到客户端
Response.WriteFile(file.FullName);
// 停止页面的执行
Response.Flush();
Response.End(); }
catch (Exception ex)
{
ExceptionLogger.LogException("SaleReport.ButtonDummy_Click", new ZeroGlobalException(ExceptionType.UnknownError.ToString(), ex));
}
}
我会从数据库中读取出文件路径,并存放在textbox中,然后点击一个按钮打开这个路径的文件.
请给出功能代码.谢谢
{
try
{
//导出数据
string name = DateTime.Now.ToString("yyyymmddhhmmss");
//这里改成你文本框控件
string path = this.txtPath.Text.Trim();
ToExcel(path); System.IO.FileInfo file = new System.IO.FileInfo(path);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", file.Length.ToString()); // 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/ms-excel"; // 把文件流发送到客户端
Response.WriteFile(file.FullName);
// 停止页面的执行
Response.Flush();
Response.End(); }
catch (Exception ex)
{
ExceptionLogger.LogException("SaleReport.ButtonDummy_Click", new ZeroGlobalException(ExceptionType.UnknownError.ToString(), ex));
}
}
解决方法,在发布目录下建立固定文件夹存放文件。
输入路径是剔除K:\,改为服务器路径。
问题解决。
我没有把文件上传到IIS,而是把文件的路径存进了数据库,每次需要看文件直接打开这个路径的文件就可以了,如果文件不存在或者没权限看这个路径不是程序控制的问题.
我只想点击view按钮就可以打开文本控件内路径的文件.