图片的保存

来源:互联网 发布:java基础深度书籍推荐 编辑:程序博客网 时间:2024/05/05 12:55

string fullpath = this.txtFile.Value; string fileName = fullpath.Substring(fullpath.LastIndexOf("//") + 1); string alias = fileName.Substring(fileName.LastIndexOf(".") + 1); string newname = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + "." + alias; prize.url = newname; 插入数据库中 txtFile.PostedFile.SaveAs(GetUploadPath(newname)); /// /// 返回文件路径 /// ////// public string GetUploadPath(string filename) { string Path = ""; string uploadPath = Page.Request.PhysicalApplicationPath + "Manager//Prize//prize//";//文件路径 Path = ReturnFilePath(uploadPath, filename); return Path; } /// /// 创建路径 /// ///////// public string ReturnFilePath(string uploadPath, string fileName) { string filePath = uploadPath + fileName; if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } return filePath; }