LiuQiang.Net(38478374) 10:41:28
string path = Server.MapPath( "~/upload/ ");
string filepath = path + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Millisecond.ToString() + System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
FileUpload1.SaveAs(filepath);
想变成相对路径该咋办?
现在上传后的路径是D:\tsinghua\upload\2007951057562.gif
我想让他变成upload\2007951057562.gif放入数据库
------解决方案--------------------------------------------------------
up
------解决方案--------------------------------------------------------
这样做肯定是不行的 如果硬要这样做 你可以直接用 upload/+ "你的文件名 "
------解决方案--------------------------------------------------------
同意楼上,重拼下字符串不就行了?
------解决方案--------------------------------------------------------
用getfliename方法取出文件名,然后构造 "upload/文件名 "字符串,将这个字符串存到数据库即可
只能由相对转绝对,不能有绝对转相对
------解决方案--------------------------------------------------------
重组字符串不就行了。
string path = Server.MapPath( "~/upload/ ");
string FileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Millisecond.ToString() + System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
string filepath = path + FileName;
FileUpload1.SaveAs(filepath);
string 存入数据库的字段 = "upload/ " + FileName;