コード例 #1
0
    /// <summary>
    /// 현재 Assembly 가 존재하는 물리적 폴더명을 반환합니다.
    /// </summary>
    /// <returns></returns>
    internal static string GetEntryAssemblyFolderName()
    {
        string returnResult = string.Empty;

        try
        {
            string   entryAssemblyName = "Nameless";
            string[] tmpArray          = null;

            if (System.Reflection.Assembly.GetEntryAssembly() != null)
            {
                // EntryAssembly 가 .exe 일 경우
                entryAssemblyName = System.Reflection.Assembly.GetEntryAssembly().CodeBase;
            }
            else
            {
                // System.Reflection.Assembly.GetEntryAssembly() 가 null 일 경우는 Web 으로 가정
                entryAssemblyName = System.Web.HttpContext.Current.Server.MapPath("~"); // + _EXECUTING_ASSEMBLY_NAME;
            }

            // .exe 가 아닐 경우 다른 방법으로 구하기 위함
            tmpArray = entryAssemblyName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

            // exe 파일의 경우 실행 파일 명을 구하고, 그 외의 경우( WEB ) /bin 한 단계 위 폴더명을 구함
            if (tmpArray != null && tmpArray[tmpArray.Length - 1] == "exe")
            {
                string[] tmp = entryAssemblyName.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);

                entryAssemblyName = tmp[tmp.Length - 1];
            }
            else
            {
                string[] tmp = entryAssemblyName.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);

                entryAssemblyName = tmp[tmp.Length - 1];
            }

            returnResult = entryAssemblyName;
        }
        catch (Exception ex)
        {
            HelperCommon.RegisterLogForHelperCommon(ex.ToString());
        }

        return(returnResult);
    }
コード例 #2
0
    /// <summary>
    /// 현재 Assembly 가 존재하는 물리적 경로를 반환합니다.
    /// </summary>
    /// <returns></returns>
    internal static string GetAssemblyConfigPath()
    {
        string returnResult = string.Empty;

        try
        {
            string   assemblyConfigPath = "Nameless";
            string[] tmpArray           = null;

            if (System.Reflection.Assembly.GetExecutingAssembly() != null)
            {
                // EntryAssembly 가 .exe 일 경우
                assemblyConfigPath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
            }
            else
            {
                // System.Reflection.Assembly.GetEntryAssembly() 가 null 일 경우는 Web 으로 가정
                assemblyConfigPath = System.Web.HttpContext.Current.Server.MapPath("~") + _EXECUTING_ASSEMBLY_NAME;
            }

            // .exe 가 아닐 경우 다른 방법으로 구하기 위함
            tmpArray = assemblyConfigPath.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

            // exe 파일의 경우 실행 파일 명을 구하고, 그 외의 경우( WEB ) /bin 한 단계 위 경로까지 구함
            if (tmpArray != null && tmpArray[tmpArray.Length - 1] == "exe")
            {
                assemblyConfigPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            }
            else
            {
                // URI 형태를 물리 경로로 변환
                string   tmpLocalPath = new Uri(assemblyConfigPath).LocalPath;
                string[] tmp          = tmpLocalPath.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);

                string tmpResult = string.Empty;

                // /BIN 의 상위 폴더명 찾기
                foreach (string n in tmp)
                {
                    if (n.ToUpper().Equals("BIN"))
                    {
                        // /bin 의 상위 폴더 경로 + Assembly Name
                        tmpResult += _EXECUTING_ASSEMBLY_NAME;
                        break;
                    }

                    tmpResult += n + "\\";
                }

                assemblyConfigPath = tmpResult;
            }

            returnResult = assemblyConfigPath;
        }
        catch (Exception ex)
        {
            HelperCommon.RegisterLogForHelperCommon(ex.ToString());
        }

        return(returnResult);
    }