public static void Upgrade() { string updateFolder = AppDomain.CurrentDomain.BaseDirectory + Common.APPLICATION_ID; FileAdapter.EnsurePath(updateFolder); FileAdapter.Copy(Updater.AppName, updateFolder + @"\" + Updater.AppName, true); foreach (var file in Updater.DepandenceFiles) { FileAdapter.Copy(file, AppDomain.CurrentDomain.BaseDirectory + Common.APPLICATION_ID + @"\" + file, true); } string updateEndPoint = INIAdapter.ReadValue(Common.CFG_SECTION_WEB, Common.CFG_KEY_UPDATE_END_POINT, Common.CFG_FILE_PATH); string args = String.Format("-n {0} -v {1} -c {2}", AppAdapter.GetName(), VersionAdapter.GetPureVersion(VersionType.ASSEMBLY), updateEndPoint + "/" + Common.APPLICATION_ID); System.Diagnostics.Process.Start(updateFolder + @"\" + Updater.AppName, args); }
static void PrepareAppEnvironment() { Assembly assem = Assembly.GetExecutingAssembly(); log4net.Config.XmlConfigurator.Configure(assem.GetManifestResourceStream("SmartLife.Client.Merchant.log4net.config")); FileAdapter.EnsurePath(Common.SOUND_FILE_PATH); if (!FileAdapter.Exists(Common.DEFAULT_SOUND_NAME_OF_DEALING)) { using (FileStream fs = new FileStream(Common.DEFAULT_SOUND_NAME_OF_DEALING, FileMode.Create)) { byte[] data = new byte[Properties.Resources.Dealing.Length]; Properties.Resources.Dealing.Read(data, 0, data.Length); fs.Write(data, 0, data.Length); } } if (!FileAdapter.Exists(Common.DEFAULT_SOUND_NAME_OF_WAIT_RESPONSE)) { using (FileStream fs = new FileStream(Common.DEFAULT_SOUND_NAME_OF_WAIT_RESPONSE, FileMode.Create)) { byte[] data = new byte[Properties.Resources.WattingResponse.Length]; Properties.Resources.WattingResponse.Read(data, 0, data.Length); fs.Write(data, 0, data.Length); } } if (!FileAdapter.Exists(Common.DEFAULT_SOUND_NAME_OF_WEIXING)) { using (FileStream fs = new FileStream(Common.DEFAULT_SOUND_NAME_OF_WEIXING, FileMode.Create)) { byte[] data = new byte[Properties.Resources.WeiXing.Length]; Properties.Resources.WeiXing.Read(data, 0, data.Length); fs.Write(data, 0, data.Length); } } }
public void ProcessRequest(HttpContext context) { //context.Response.ContentType = "text/plain"; //context.Response.Charset = "utf-8"; //HttpPostedFile file = context.Request.Files["Filedata"]; //if (file != null) //{ // string saveName = @context.Request["saveName"]; // string fileType = file.FileName.Substring(file.FileName.LastIndexOf(".")); // //string uploadPath = HttpContext.Current.Server.MapPath(@context.Request["folder"]); // //创建文件目录 // string virpath = context.Request.Form["folderPath"]; // if (string.IsNullOrEmpty(virpath)) { // virpath = @context.Request["folder"]; // } // //设置虚拟目录URL // string virDirectorySite = "../../ContentServices"; // //获取站点文件路径 // string rootpath = HttpContext.Current.Server.MapPath(virDirectorySite); // string uploadPath = HttpContext.Current.Server.MapPath(virDirectorySite + virpath); // if (!string.IsNullOrEmpty(uploadPath)) { // uploadPath += @"\" + DateTime.Now.ToString("yyyy-MM"); // } // FileAdapter.EnsurePath(uploadPath); // //是否生成缩略图 // bool bThumb = false; // if (!string.IsNullOrEmpty(context.Request.Form["bThumb"])) { // bThumb = true; // } // //文件名 // string filename = file.FileName; // string extname = filename.Substring(filename.LastIndexOf(".") + 1); // string strSaveName = filename.Substring(0, filename.LastIndexOf(".")) + "_" + context.Request.Form["ResidentName"] + "_" + DateTime.Now.ToString("yyyyMMddHHmmss"); // string strSaveThumbName = strSaveName + "_mini"; // string filepath = "", thumbfilepath = ""; // if (string.IsNullOrEmpty(saveName)) // { // filepath = uploadPath + "\\" + strSaveName + fileType; // if (bThumb) // { // thumbfilepath = uploadPath + "\\" + strSaveThumbName + fileType; // } // } // else // { // filepath = uploadPath + "\\" + saveName + fileType; // } // //保存原图 // file.SaveAs(filepath); // string retError = ""; //判断是否成功生成缩略图 // if (!string.IsNullOrEmpty(thumbfilepath)) // { // retError = MakeThumbnail(filepath, thumbfilepath, 80, 80, "cut", extname); //保存缩略图 // } // if (string.IsNullOrEmpty(retError)) { // Attachment attachment = new Attachment(); // attachment.AttachmentId = Guid.NewGuid(); // attachment.OriginName = filename; // attachment.SourceTable = context.Request.Form["SourceTable"]; // attachment.SourceId = context.Request.Form["ResidentId"]; // attachment.AttachmentTag = context.Request.Form["AttachmentTag"]; // attachment.Suffix = extname; // attachment.AttachmentSize = file.ContentLength; // attachment.SaveName = filepath.Replace(rootpath, "").Replace("\\", "/"); // attachment.SaveThumbName = thumbfilepath.Replace(rootpath, "").Replace("\\", "/"); // if (SaveImgInfo(attachment)) // { // //context.Response.Write(attachment.ToJson()); // } // else { // context.Response.Write("0"); // } // } // //下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失 // context.Response.Write("1"); //} //else //{ // context.Response.Write("0"); //} context.Response.ContentType = "text/plain"; context.Response.Charset = "utf-8"; HttpPostedFile file = context.Request.Files["Filedata"]; if (file != null) { //创建文件目录 string virPath = context.Request.Form["virPath"]; if (string.IsNullOrEmpty(virPath)) { virPath = "/others"; } string virRoot = "ContentServices"; string virFullPath = (virPath.StartsWith("/") ? virPath : "/" + virPath); if (!virFullPath.EndsWith("/")) { virFullPath += "/"; } string dateTimeBlock = DateTime.Now.ToString("yyyy-MM"); virFullPath += dateTimeBlock; string fileSavePath = HttpContext.Current.Server.MapPath("/" + virRoot + virFullPath); FileAdapter.EnsurePath(fileSavePath); //文件名 string originName = file.FileName; string extname = originName.Substring(originName.LastIndexOf(".") + 1); string fileNamePart = originName.Substring(0, originName.LastIndexOf(".")) + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + GetRandomString(4); string fileName = fileNamePart + "." + extname; string fileThumbName = fileNamePart + "_thumb." + extname; string filepath = "", thumbfilepath = ""; filepath = fileSavePath + @"\" + fileName; //是否生成缩略图 if (needMakeThumbnail(extname)) { thumbfilepath = fileSavePath + @"\" + fileThumbName; } //保存 file.SaveAs(filepath); string retError = ""; //判断是否成功生成缩略图 if (!string.IsNullOrEmpty(thumbfilepath)) { retError = MakeThumbnail(filepath, thumbfilepath, 80, 80, "cut", extname); //保存缩略图 } string retValue = "1"; try { if (string.IsNullOrEmpty(retError)) { Attachment attachment = new Attachment(); attachment.AttachmentId = Guid.NewGuid(); attachment.OriginName = originName; attachment.SourceTable = context.Request.Form["SourceTable"]; attachment.SourceId = context.Request.Form["ArticleId"]; attachment.AttachmentTag = context.Request.Form["AttachmentTag"]; attachment.Suffix = extname; attachment.AttachmentSize = file.ContentLength; attachment.SaveName = virFullPath + "/" + fileName; attachment.SaveThumbName = virFullPath + "/" + fileThumbName; BuilderFactory.DefaultBulder(context.Request.Form["ConnectId"]).Create <Attachment>(attachment); retValue = attachment.AttachmentId.ToString(); } } catch (Exception ex) { } //下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失 context.Response.Write(retValue); } else { context.Response.Write("0"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Charset = "utf-8"; //文件保存目录路径 String savePath = "/CMU/Article"; //定义允许上传的文件扩展名 Hashtable extTable = new Hashtable(); extTable.Add("image", "gif,jpg,jpeg,png,bmp"); extTable.Add("flash", "swf,flv"); extTable.Add("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb"); extTable.Add("file", "doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2,pdf"); //最大文件大小 int maxSize = 1000000; this.context = context; HttpPostedFile imgFile = context.Request.Files["imgFile"]; if (imgFile == null) { showError("请选择文件。"); } String dirPath = context.Server.MapPath(savePath); String dirName = context.Request.QueryString["dir"]; if (String.IsNullOrEmpty(dirName)) { dirName = "image"; } if (!extTable.ContainsKey(dirName)) { showError("目录名不正确。"); } String fileName = imgFile.FileName; String fileExt = Path.GetExtension(fileName).ToLower(); if (imgFile.InputStream == null || imgFile.InputStream.Length > maxSize) { showError("上传文件大小超过限制。"); } if (String.IsNullOrEmpty(fileExt) || Array.IndexOf(((String)extTable[dirName]).Split(','), fileExt.Substring(1).ToLower()) == -1) { showError("上传文件扩展名是不允许的扩展名。\n只允许" + ((String)extTable[dirName]) + "格式。"); } //创建文件夹 //设置虚拟目录URL string virDirectorySite = "../../ContentServices"; //获取站点文件路径 string rootpath = HttpContext.Current.Server.MapPath(virDirectorySite); string uploadPath = HttpContext.Current.Server.MapPath(virDirectorySite + savePath); if (!string.IsNullOrEmpty(uploadPath)) { uploadPath += @"\" + DateTime.Now.ToString("yyyy-MM"); } FileAdapter.EnsurePath(uploadPath); //文件名 string strSaveName = fileName.Substring(0, fileName.LastIndexOf(".")) + "_" + DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt; string filepath = uploadPath + "\\" + strSaveName; //保存原图 imgFile.SaveAs(filepath); Hashtable hash = new Hashtable(); hash["error"] = 0; hash["url"] = "../" + virDirectorySite + savePath + "/" + DateTime.Now.ToString("yyyy-MM") + "/" + strSaveName; string aa = "gif,jpg,jpeg,png,bmp"; if (Array.IndexOf(aa.Split(','), fileExt.Substring(1).ToLower()) != -1) { Image imggg = Image.FromFile(filepath); if (imggg.Width > 500) { imggg.Dispose(); MakeThumbnail(filepath, filepath, 500, 300, "W", fileExt); } if (imgFile.InputStream == null || imgFile.InputStream.Length > 500 * 1024) { MakeThumbnail(filepath, filepath, 500, 300, "W", fileExt); } } context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8"); context.Response.Write(hash.ToJson()); context.Response.End(); }