在aspx中如何写代码,点击按钮打开指定路径的文件(在文本框中的),例如:K:\123.xls,K是网络map盘.

解决方案 »

  1.   

    用file控件  
    <input id="File1" type="file" />
      

  2.   

    我倒,误会了,如果要打开相应的文件,要装相应的插件,vs的com+提供了很多,对excel文件的打开网上搜索的到N多的
      

  3.   

      
     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));
                }
            }
      

  4.   

    我的这个文件并不是在IIS服务器上,是其他的路径,有没有方法直接open这个路径的文件就可以了
      

  5.   

    string path ="IPaddress"+filefullname;
      

  6.   

    必须知道IP地址或者服务器名。用"http://www.***.com"+fullname;也可以的
      

  7.   

    我写成这样,也可以打开<a href="file://K:\IT\123.xls">test</a>但是不能把txtbox中的值传给它.
      

  8.   

    三尾,
    我会从数据库中读取出文件路径,并存放在textbox中,然后点击一个按钮打开这个路径的文件.
    请给出功能代码.谢谢
      

  9.   

    代码基本已经给了 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));
                }
            }
      

  10.   

    大哥,你没放到iis的发布目录下匿名用户是没有权限打开的,
    解决方法,在发布目录下建立固定文件夹存放文件。
    输入路径是剔除K:\,改为服务器路径。
    问题解决。
      

  11.   

    可能是我没描述清楚,
    我没有把文件上传到IIS,而是把文件的路径存进了数据库,每次需要看文件直接打开这个路径的文件就可以了,如果文件不存在或者没权限看这个路径不是程序控制的问题.
    我只想点击view按钮就可以打开文本控件内路径的文件.