FileUpload怎么自定义上传的文件名
filename = time + FileUpload1.FileName;
address = path + filename;
FileUpload1.PostedFile.SaveAs(address);
提示不支持给定的路径格式
我想上传文件的时候把文件名加上时间,以确保文件名的唯一性,但是saveas的出了问题,求大神帮解决
------解决方案-------------------- string loadFile = fileUpload1.PostedFile.FileName;
string fileExtension = loadFile.Substring(loadFile.LastIndexOf("."));
string newFileName = Guid.NewGuid().ToString() + fileExtension;
string file = Server.MapPath("~/Files/" + newFileName);
fileUpload1.SaveAs(file);
就是这样啦,每次产生的文件名都不同
------解决方案--------------------string Sion = Path.GetExtension(this.FileUpload1.FileName);
string ServerPath = Server.MapPath(@"~/uploads");
string FileName = DateTime.Now.ToString("yyyyMMddHHmmssFFFFF") + this.FileUpload1.FileName ;
string SaveFilePath = ServerPath + "/" + FileName;
this.FileUpload1.PostedFile.SaveAs(SaveFilePath);