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;
}
}
}
}