使用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;//数据库存放路径
}