Esempio n. 1
0
        // 文件上传完毕时操作
        void fileUpload_FileUploadCompleted(object sender, FileUploadCompletedEventArgs args)
        {
            string fileName = "";

            OuterServiceFO fsFO = new OuterServiceFO();

            try
            {
                FileInfo fi = new FileInfo(args.FilePath);
                string   completedFileName = UploadFileInfo.GetAppCompletedFileName(fileInfo.FileName, DateTime.Now);
                string   targetFile        = Path.Combine(fi.Directory.FullName, completedFileName);


                string relateId = HttpContext.Current.Request.QueryString["RelateId"];
                string src      = HttpContext.Current.Request.QueryString["Src"];

                long fileSize = fi.Length;

                fileName = fsFO.AddLocalFile(fi.FullName, completedFileName, relateId, "", "", src, true);

                ctx.Response.ContentEncoding = Encoding.Unicode;
                ctx.Response.Write(fileName + "_" + fileSize.ToString());
                ctx.Response.Flush();
            }
            catch (Exception exp)
            {
                if (fileName != "")
                {
                    fsFO.DelFiles(fileName, string.Format("Upload页面错误,{0}", exp.Message).Substring(0, 200));
                    FileInfo file = new FileInfo(args.FilePath);
                    file.Delete();
                }

                ctx.Response.ContentEncoding = Encoding.Unicode;
                ctx.Response.Write("error:" + exp.Message);
                ctx.Response.Flush();
            }


            this.WriteLog("Upload End");
        }
Esempio n. 2
0
        string GetTempFolder(string filename, string src, long fileLength)
        {
            string cacheKey = string.Format("{0}_{1}_{2}", filename, src, fileLength);

            cacheKey = cacheKey.GetHashCode().ToString();
            object obj = HttpContext.Current.Cache.Get(cacheKey);

            if (obj == null)
            {
                OuterServiceFO fsFO       = new OuterServiceFO();
                string         rootPath   = fsFO.GetAvailableRootFolder(src, Path.GetExtension(filename).Trim('.'));
                string         tempFolder = Path.Combine(rootPath, "TempFolder");
                if (!Directory.Exists(tempFolder))
                {
                    Directory.CreateDirectory(tempFolder);
                }

                HttpContext.Current.Cache.Insert(cacheKey, tempFolder);

                return(tempFolder);
            }
            return(obj.ToString());
        }