///
/// 上传图片方法
/// </summary>
/// FileUpload控件</param>
/// 预览图片img的名字</param>
/// 上传图片的路径</param>
///
public string AddImg(FileUpload linkImg, HtmlImage links, string file)
{
string img = "";
if (linkImg.HasFile)//检查是否有文件
{
string fullFileName = linkImg.PostedFile.FileName; //文件路径名
string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1); //图片名称
string type = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1); //图片格式
if (type == "jpg" || type == "JPG" || type == "gif" || type == "GIF" || type == "BMP" || type == "bmp" || type == "BNG" || type == "png") //判断是否为图片类型
{
string path = HttpContext.Current.Request.MapPath("~/" + file + "/");//获取上传文件的网站目录路径
linkImg.SaveAs(path + fileName);//存储文件到磁盘
if (links != null)
{
links.Src ="~/" + file + "/" + fileName;//显示图片
}
img ="~/"+ file + "/" + fileName;
}
else
{
HttpContext.Current.Response.Write("