CS获取可执行文件所在文件夹

        //Form程序
        private static String getExeFileFolder()
        {
            String strExeFolder = System.Reflection.Assembly.GetExecutingAssembly().Location;
            int nPos = strExeFolder.LastIndexOf("\\");
            if (nPos >= 0)
            {
                strExeFolder = strExeFolder.Substring(0, nPos + 1);
            }
            else
            {
                strExeFolder = strExeFolder + "\\";
            }

            return strExeFolder;
        }

        //IIS程序
        String rootPath = Request.PhysicalApplicationPath;
        String strExeFolder = getExeFileFolder(rootPath);
        private static String getExeFileFolder(String strExeFolder)
        {
            int nPos = strExeFolder.LastIndexOf("\\");
            if (nPos >= 0)
            {
                strExeFolder = strExeFolder.Substring(0, nPos + 1);
            }
            else
            {
                strExeFolder = strExeFolder + "\\";
            }

            return strExeFolder;
        }

Leave a Reply

Your email address will not be published. Required fields are marked *

*