我想得到文件的全路径,但好像是有IE6能得到,IE7,IE8和firefox都不能得到全路径,只能得到文件名,求一解决方法,只要能得到全路径就行,来个高手啊,拜求啊!

解决方案 »

  1.   

    用变通的方法, 在 fileupload 的选择事件(js)里,js + 隐藏域 
      

  2.   

    哥们你这样去试试浏览器--internt选项--安全---internet----自定义设置----- 里面 将文件上传到服务器时包含本地目录路径  选择 启用,则上传的包含有路径,如果禁用,就不包含路径 
      

  3.   

    string fpath = Server.MapPath("upfile") + "\\" + name;using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string name = FileUpload1.FileName;//上传文件名字
            string size = FileUpload1.PostedFile.ContentLength.ToString();
            string type = FileUpload1.PostedFile.ContentType;
            string type2 = name.Substring(name.LastIndexOf(".") + 1);
            string ipath = Server.MapPath("upimg") + "\\" + name;
            string fpath = Server.MapPath("upfile") + "\\" + name;
            string path="F:\\aaa\\"+FileUpload1.FileName;
            string wpath = "upimg\\" + name;
            if (type2 == "jpg" || type2 == "gif" || type2 == "bmp" || type2 == "png")
            {
                FileUpload1.SaveAs("F:\\aaa\\"+FileUpload1.FileName);
               // Image1.ImageUrl="F:\\aaa\\"+FileUpload1.FileName;
                Label1.Text = "你传图片的名字是" + name + "<br>文件大小为" + size + "<br>文件类型为" + type2 + "<br>文件路径为" + ipath;
            }
            
            SqlConnection cn = new SqlConnection("server=.;database=Northwind;uid=sa;pwd=sa");
            SqlCommand cmd = new SqlCommand("insert into Image(imageName,imagepath) values('" + name + "','" + path + "')", cn);
            cn.Open();
            cmd.ExecuteNonQuery();
            cn.Close();
        }
        protected void Button2_Click(object sender, EventArgs e)
        {    SqlConnection cn = new SqlConnection("server=.;database=Northwind;uid=sa;pwd=sa");
        SqlCommand cmd = new SqlCommand("select imageName from Image where imageID='" + Convert.ToInt32(TextBox1.Text) + "'", cn);
        cn.Open();
        string a = cmd.ExecuteScalar().ToString();
        cn.Close();
        Image1.ImageUrl = "F:\\aaa\\" + a;
         }
    }
      

  4.   

    Server.MapPath得到aspx页面在服务器上的路径配合上文件名就是完整的了
      

  5.   

    Server.MapPath是服务器的路径,不可能得到客户端的
      

  6.   

    其实我想实现的功能是把excel数据导入数据库中,用fileupload主要是获取excel的路径以便读取excel
      

  7.   

    那你不能读客户端的路径啊,客户端的路径是无法读取的。
    你必须
    文件路径这样的f = Server.MapPath("~/" + System.IO.Path.GetFileName(FileUpload1.FileName));
    fileUpload.SaveAs(f);f才是你需要的路径,跟客户端嘛关系啊
      

  8.   


    cs代码在服务器端运行,你想在服务器用客户端的物理地址操作客户端的文件,根本不可能的事。还是得乖乖把excel上传到服务器再慢慢解析吧。
      

  9.   

    你们都省省吧,net为了安全起见,控件根本不能获取到完整路径,要得到路径还得js辅助才行
      

  10.   

    我是把excel文件放在一个公共硬盘上的,不是放在我电脑上,所以实际上是不上传文件的,直接从网络盘上读取。我想要的就是excel所在的目录,也就是说完整路径