asp.net怎么上传文件并将文件路径保存到数据库呢? 10
1个回答
展开全部
使用Upload控件:
string UserDirectory = "news";//存放图片的文件夹
string UserPath = Server.MapPath("../UploadFiles").ToString() + "\\" + UserDirectory + "\\" + "新闻" + "\\" + "Img" + "\\" + DateTime.Now.ToString("yyyy") + DateTime.Now.ToString("MM");//图片存放路径
string ImgFileName;
string FileName;
string FileType;
string UploadImgName = FileUploadImg.PostedFile.FileName; //文件在本地的原始位置
FileName = UploadImgName.Substring(UploadImgName.LastIndexOf('\\') + 1).ToString();//得到文件名
FileType = UploadImgName.Substring(UploadImgName.LastIndexOf(".") + 1);//得到后缀名
if (StringFun.GetimgFileName.Getimg(FileUploadImg, UserPath, out ImgFileName))
{
imgDataUrl = "UploadFiles/" + UserDirectory + "/" + "新闻" + "/" + "Img" + "/" + DateTime.Now.ToString("yyyy") + DateTime.Now.ToString("MM") + "/" + ImgFileName;//数据库存放路径
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询