Ejemplo n.º 1
0
        private void MergeFiles(HttpContext context)
        {
            string guid      = context.Request["guid"];                              //GUID
            string filename  = context.Request["filename"];                          //文件名
            string filesize  = context.Request["filesize"];                          //文件大小
            int    Ifilesize = 0;
            string fileExt   = Utils.GetFileExt(filename);                           //文件扩展名,不含“.”

            int.TryParse(filesize, out Ifilesize);                                   //获得文件大小,以字节为单位
            string fileName    = filename.Substring(filename.LastIndexOf(@"\") + 1); //取得原文件名
            string newFileName = Utils.GetRamCode() + "." + fileExt;                 //随机生成新的文件名

            Web.UI.UpLoad upload     = new UpLoad();
            string        msg        = string.Empty;
            string        root       = context.Server.MapPath("~/Temp/");
            string        sourcePath = Path.Combine(root, guid + "/");               //源数据文件夹
            string        targetPath = Path.Combine(root, Guid.NewGuid() + fileExt); //合并后的文件
            DirectoryInfo dicInfo    = new DirectoryInfo(sourcePath);

            if (Directory.Exists(Path.GetDirectoryName(sourcePath)))
            {
                msg = upload.MergeFiles(filename, Ifilesize, dicInfo);

                DeleteFolder(sourcePath);
                //  context.Response.Write("{\"chunked\" : true, \"hasError\" : false, \"savePath\" :\"" + System.Web.HttpUtility.UrlEncode(targetPath) + "\"}");
                //context.Response.Write(msg);
            }
            //返回成功信息
            context.Response.Write(msg);
            context.Response.End();
        }