Пример #1
0
        /// <summary>
        /// 删除内容图片
        /// </summary>
        /// <param name="content">内容</param>
        /// <param name="startstr">匹配开头字符串</param>
        public static void DeleteContentPic(string content, string startstr)
        {
            if (string.IsNullOrEmpty(content))
            {
                return;
            }
            Regex           reg = new Regex("IMG[^>]*?src\\s*=\\s*(?:\"(?<1>[^\"]*)\"|'(?<1>[^\']*)')", RegexOptions.IgnoreCase);
            MatchCollection m   = reg.Matches(content);

            foreach (Match math in m)
            {
                string imgUrl   = math.Groups[1].Value;
                string fullPath = Utils.GetMapPath(imgUrl);
                try {
                    if (imgUrl.ToLower().StartsWith(startstr.ToLower()) && File.Exists(fullPath))
                    {
                        FileHelp.DeleteFile(fullPath);
                    }
                } catch { }
            }
        }
Пример #2
0
        /// <summary>
        /// 删除本地上传的文件(及缩略图)
        /// </summary>
        /// <param name="_filepath"></param>
        public static void DeleteUpFile(string _filepath)
        {
            if (string.IsNullOrEmpty(_filepath))
            {
                return;
            }
            string fullpath = Utils.GetMapPath(_filepath); //原图

            if (File.Exists(fullpath))
            {
                FileHelp.DeleteFile(fullpath);
            }
            if (_filepath.LastIndexOf("/") >= 0)
            {
                string thumbnailpath = _filepath.Substring(0, _filepath.LastIndexOf("/")) + "mall_" + _filepath.Substring(_filepath.LastIndexOf("/") + 1);
                string fullTPATH     = Utils.GetMapPath(thumbnailpath); //宿略图
                if (File.Exists(fullTPATH))
                {
                    FileHelp.DeleteFile(fullTPATH);
                }
            }
        }