关于fileupload路径问题 我想得到文件的全路径,但好像是有IE6能得到,IE7,IE8和firefox都不能得到全路径,只能得到文件名,求一解决方法,只要能得到全路径就行,来个高手啊,拜求啊! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用变通的方法, 在 fileupload 的选择事件(js)里,js + 隐藏域 哥们你这样去试试浏览器--internt选项--安全---internet----自定义设置----- 里面 将文件上传到服务器时包含本地目录路径 选择 启用,则上传的包含有路径,如果禁用,就不包含路径 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; }} Server.MapPath得到aspx页面在服务器上的路径配合上文件名就是完整的了 Server.MapPath是服务器的路径,不可能得到客户端的 其实我想实现的功能是把excel数据导入数据库中,用fileupload主要是获取excel的路径以便读取excel 那你不能读客户端的路径啊,客户端的路径是无法读取的。你必须文件路径这样的f = Server.MapPath("~/" + System.IO.Path.GetFileName(FileUpload1.FileName));fileUpload.SaveAs(f);f才是你需要的路径,跟客户端嘛关系啊 cs代码在服务器端运行,你想在服务器用客户端的物理地址操作客户端的文件,根本不可能的事。还是得乖乖把excel上传到服务器再慢慢解析吧。 你们都省省吧,net为了安全起见,控件根本不能获取到完整路径,要得到路径还得js辅助才行 我是把excel文件放在一个公共硬盘上的,不是放在我电脑上,所以实际上是不上传文件的,直接从网络盘上读取。我想要的就是excel所在的目录,也就是说完整路径 程序放到服务器上,访问不了...能不能帮帮忙啊! UI界面在企业级系统中应用,到底应该用什么,大家有什么好的UI看看 恳求Asp.Net2.0的无刷新二级或三级代码,100分送上 FCKeditor中的内容怎么保存不进数据库呢? 莱鸟的问题 怎么样在新增新闻的时候生成静态的新闻页面??? asp.net新手提问,关于多条件查询的问题 100分相送,求解决身份验证问题,挺难的,如解决送全分 菜鸟提问,高手请指教 在线给分 .net2.0对WORD的操作,本地上Ok,挂伺服器就报黄页,请高手指点 缓存技术
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;
}
}
你必须
文件路径这样的f = Server.MapPath("~/" + System.IO.Path.GetFileName(FileUpload1.FileName));
fileUpload.SaveAs(f);f才是你需要的路径,跟客户端嘛关系啊
cs代码在服务器端运行,你想在服务器用客户端的物理地址操作客户端的文件,根本不可能的事。还是得乖乖把excel上传到服务器再慢慢解析吧。