Ejemplo n.º 1
0
        /// <summary>
        /// 复制文件
        /// </summary>
        /// <param name="hpFile"></param>
        /// <param name="pmb"></param>
        /// <returns></returns>
        public static String CopyFile(Resource_FilesStatus Resource_File, PortalModuleBase pmb)
        {
            String   WebFilePath  = Resource_File.url;
            String   SaveFilePath = pmb.MapPath(WebFilePath);
            FileInfo SaveFile     = new FileInfo(SaveFilePath);



            String FileName = Resource_File.name.Replace(" ", "_");

            if (FileName.IndexOf(@"\") >= 0)
            {
                FileName = FileName.Substring(FileName.LastIndexOf(@"\"), FileName.Length - FileName.LastIndexOf(@"\")).Replace(@"\", "");
            }

            String Extension = Path.GetExtension(FileName).Replace(".", "");


            //构造保存路径
            String   FileUrl = FileName;
            FileInfo file    = new FileInfo(pmb.MapPath(String.Format("~/Portals/{0}/PowerForms/{1}/{2}", pmb.PortalId, pmb.ModuleId, FileName)));

            if (!file.Directory.Exists)
            {
                file.Directory.Create();
            }

            int ExistsCount = 1;

            //检测文件名是否存在
            while (file.Exists)
            {
                FileUrl = String.Format("{0}_{1}.{2}", FileName.Replace("." + Extension, ""), ExistsCount, Extension);
                file    = new FileInfo(pmb.MapPath(String.Format("~/Portals/{0}/PowerForms/{1}/{2}", pmb.PortalId, pmb.ModuleId, FileUrl)));
                ExistsCount++;
            }

            //保存文件到文件夹
            SaveFile.MoveTo(file.FullName);

            return(FileUrl);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="hpFile"></param>
        /// <param name="pmb"></param>
        /// <returns></returns>
        public static String UploadFile(HttpPostedFile httpFile, PortalModuleBase pmb)
        {
            String FileName = httpFile.FileName.Replace(" ", "_");

            if (FileName.IndexOf(@"\") >= 0)
            {
                FileName = FileName.Substring(FileName.LastIndexOf(@"\"), FileName.Length - FileName.LastIndexOf(@"\")).Replace(@"\", "");
            }

            String Extension = Path.GetExtension(FileName).Replace(".", "");


            //构造保存路径
            String   FileUrl = FileName;
            FileInfo file    = new FileInfo(pmb.MapPath(String.Format("~/Portals/{0}/PowerForms/{1}/{2}", pmb.PortalId, pmb.ModuleId, FileName)));

            if (!file.Directory.Exists)
            {
                file.Directory.Create();
            }

            int ExistsCount = 1;

            //检测文件名是否存在
            while (file.Exists)
            {
                FileUrl = String.Format("{0}_{1}.{2}", FileName.Replace("." + Extension, ""), ExistsCount, Extension);
                file    = new FileInfo(pmb.MapPath(String.Format("~/Portals/{0}/PowerForms/{1}/{2}", pmb.PortalId, pmb.ModuleId, FileUrl)));
                ExistsCount++;
            }

            //保存文件到文件夹
            httpFile.SaveAs(file.FullName);

            return(FileUrl);
        }