日期:2014-05-17 浏览次数:20453 次
/// <summary> /// 返回要保存的文件路径 /// </summary> /// <returns></returns> [WebMethod] public string Fileupload() { string savePath = ""; string fileName = txtLogoPath.FileName;//获取准备上传的文件的名称 string filePath = txtLogoPath.PostedFile.FileName;//获取准备上传文件的物理路径 try { int length = txtLogoPath.PostedFile.ContentLength;//获取准备上传的文件的大小 if (length < 2000000)//当文件小于2000000字节,即2M时: { string exec = Path.GetExtension(fileName);//获取文件的后缀名 if (exec.ToUpper() == ".GIF" || exec.ToUpper() == ".JPG" || exec.ToUpper() == ".JPEG" || exec.ToUpper() == ".PNG" || exec.ToUpper() == ".BMP") { string newName = DateTime.Now.ToString("yyyyMMddhhmmss") + DateTime.Now.Millisecond.ToString() + exec; //完整路径 savePath = @"../../images/BusinessLogo/" + newName;//数据库储存的路径 txtLogoPath.SaveAs(Server.MapPath(@"/images/BusinessLogo/" + newName));//实际保存的路径 ViewState["Conver"] = newName; } else if (exec.ToUpper() == "" || exec.ToUpper() == null) { savePath = "../../images/BusinessLogo/BaseLine.png"; }// Response.Write("{\"state\":\"0\",\"errMess\":\"请选择Logo文件!\"}"); Response.End(); } else { Response.Write("{\"state\":\"2\",\"errMess\":\"\"}"); Response.End(); } } else { Response.Write("{\"state\":\"3\",\"errMess\":\"\"}"); Response.End(); } } catch (Exception ex) { Common.MessageBox(this, "保存文件失败,详细信息为:" + ex.Message); } return savePath; }