Exemplo n.º 1
0
        public static void Delete(string sPath)
        {
            string[] strFiles = Directory.GetFiles(sPath);
            foreach (string strFile in strFiles)
            {
                try
                {
                    CFile.Delete(strFile);
                }
                catch { }
            }
            string[] strDirs = Directory.GetDirectories(sPath);
            foreach (string strDir in strDirs)
            {
                try
                {
                    Delete(strDir);
                }
                catch { }
            }
            FileInfo f = new FileInfo(sPath);

            f.Attributes = FileAttributes.Normal;
            Directory.Delete(sPath);
        }
Exemplo n.º 2
0
        public static string ReplaceIncTag(string sContent, string sPath)
        {
            Regex           regex = new Regex("<!--#include virtual=\"(.*?)\".*?-->", RegexOptions.Singleline);
            MatchCollection mc    = regex.Matches(sContent);

            if (mc.Count == 0)
            {
                return(sContent);
            }
            string incPath    = string.Empty;
            string incContent = string.Empty;

            for (int i = 0; i < mc.Count; i++)
            {
                incContent = string.Empty;
                incPath    = mc[i].Groups[1].Value;
                if (incPath.StartsWith("/"))
                {
                    incPath = System.Web.HttpContext.Current.Server.MapPath(incPath);
                }
                else if (incPath.StartsWith("../"))
                {
                    incPath = sPath.TrimEnd(new char[] { '\\' }) + @"\..\" + incPath.Replace("/", "\\");
                }
                else
                {
                    incPath = sPath.Substring(0, sPath.LastIndexOf(@"\") + 1) + incPath;
                }
                if (System.IO.File.Exists(incPath))
                {
                    incContent = CFile.Read(incPath);
                    incContent = ReplaceIncTag(incContent, incPath);
                }
                sContent = sContent.Replace(mc[i].Value, incContent);
            }
            return(sContent);
        }