Web服务器文件删除 - FileDelete

2017-01-26 09:28:38  访问(1446) 赞(0) 踩(0)


        /// <summary>
        /// Web服务器文件删除 - FileDelete 
        /// </summary>
        /// <param name="hc">HttpContext(网页信息)</param>
        /// <param name="rootDir">如果地址表达式不是~/开头,在填充rootDir(存放根目录)</param>
        /// <param name="str">文件路径</param>
        public void FileDelete(HttpContext hc, string rootDir,string str)
        {
            if (str == null)
                return;

            str = str.Trim();

            if (str.Length == 0)
                return;

            if(hc==null)
                hc =HttpContext.Current;

            if(hc == null)
                return;

            string fullName = null;

            if (str.StartsWith("~/"))
            {
                fullName = hc.Request.PhysicalApplicationPath + str.Substring(2);
            }
            else
            {
                fullName = hc.Request.PhysicalApplicationPath + rootDir + "/" + str;
            }

            if (File.Exists(fullName))
                File.Delete(fullName);
        }


标签:Web服务器文件删除 - FileDelete 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)