FolderHelper.cs帮助生成文件夹

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Web;
using System.IO;

namespace A
{
    public class FolderHelper
    {
        /// <summary>
        /// 检查或生成目录
        /// 自动检测目录支持物理目录
        /// Web目录,如果Web目录不存在 会使用Server.MapPath("~/")取Web应用程序根目录
        /// 自动在目录后加上"/"
        /// </summary>
        /// <param name="appSettName">AppSettingName,如果为空则以AppSettingName为目录名称</param>
        /// <param name="create">如果目录不存在便创建</param>
        /// <returns></returns>
        public static String GetAppSettingFolder(String folderName, bool create)
        {
            String resumeOut = folderName;
            if (resumeOut == null)
            {
                resumeOut = String.Empty;
            }
            resumeOut = resumeOut.Trim();
            bool isPhPath = false; //是否已经是物理路径
            if (resumeOut.Length > 3)
            {
                if (Char.IsLetter(resumeOut[0]) &&
                    resumeOut[1] == ':'
                    && resumeOut[2] == '//') //E:/
                {
                    isPhPath = true;
                }
            }
            if (!Directory.Exists(resumeOut))
            {
                if (HttpContext.Current != null)
                {

                    try
                    {
                        if (!isPhPath)
                        {
                            resumeOut = HttpContext.Current.Server.MapPath("~/" + resumeOut);
                        }
                    }
                    catch { }
                }
                else
                {
                    if (!isPhPath)
                    {
                        resumeOut = System.AppDomain.CurrentDomain.BaseDirectory + "//" + resumeOut;
                    }
                }
            }  
            if (!Directory.Exists(resumeOut)&&create)
            {
                Directory.CreateDirectory(resumeOut);
            }

            return resumeOut;
        }

        public static String GetAppSettingFolder(String folderName)
        {
            return GetAppSettingFolder(folderName, false);
        }


        static String _ResumeOutFolder = String.Empty;
        /// <summary>
        /// 简历导出文件夹
        /// </summary>
        public static String ResumeOutFolder
        {
            get
            {
                if (_ResumeOutFolder == String.Empty)
                {
                    _ResumeOutFolder = FolderHelper.GetAppSettingFolder(ConfigurationManager.AppSettings["ResumeOutFolder"], true);
                }
                return _ResumeOutFolder;
            }
        }

        static String _ZipOutFolder = String.Empty;
        /// <summary>
        /// 打包文件夹
        /// </summary>
        public static String ZipOutFolder
        {
            get
            {
                if (_ZipOutFolder == String.Empty)
                {
                    _ZipOutFolder = FolderHelper.GetAppSettingFolder(ConfigurationManager.AppSettings["ZipOutFolder"], true);
                }
                return _ZipOutFolder;
            }
        }
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值