public static void DeleteImage(string imageid) { List <string> ls = VTSCommon.LoadTextToList(string.Concat(ConfigHelper.BaseDirectory, "imagedata.txt"), true); string str = ls.Find(x => x.StartsWith(imageid)); string[] arr = str.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (arr != null) { if (arr.Length == 4 || arr.Length == 6) { if (System.IO.File.Exists(ConfigHelper.BaseDirectory + arr[2])) { System.IO.File.Delete(ConfigHelper.BaseDirectory + arr[2]); } } } ls.Remove(str); using (System.IO.StreamWriter sw = new System.IO.StreamWriter(string.Concat(ConfigHelper.BaseDirectory, "imagedata.txt"), false)) { foreach (string item in ls) { sw.WriteLine(item); } } }
public static List <FBImageInfo> LoadFBImage(string path) { List <FBImageInfo> list = new List <FBImageInfo>(); List <string> ls = VTSCommon.LoadTextToList(path, true); //字段分割数组 string[] arr; FBImageInfo info = null; foreach (string item in ls) { arr = item.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); //为了兼容以前的需要判断 if (arr != null) { if (arr.Length == 4) { info = new FBImageInfo() { ImageID = long.Parse(arr[0]), ImageName = arr[1], RelativePath = arr[2], ImageSkipUrl = arr[3], ImageTitle = "title", ImageAlt = "alt" }; } if (arr.Length == 6) { info = new FBImageInfo() { ImageID = long.Parse(arr[0]), ImageName = arr[1], RelativePath = arr[2], ImageSkipUrl = arr[3], ImageTitle = arr[4], ImageAlt = arr[5] }; } } list.Add(info); } return(list.OrderByDescending(x => x.ImageID).ToList()); }
public static void SaveImage(string imageid, string skipurl, string title = "title", string alt = "alt") { List <string> ls = VTSCommon.LoadTextToList(string.Concat(ConfigHelper.BaseDirectory, "imagedata.txt"), true); //获取信息 string str = ls.Find(x => x.StartsWith(imageid)); ls.Remove(str); //逐个修改字段的值 if (!string.IsNullOrEmpty(str)) { string[] arr = str.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (arr != null) { if (arr.Length == 4) { arr[3] = skipurl; str = string.Concat(arr[0], "|", arr[1], "|", arr[2], "|", arr[3], "|", title, "|", alt); ls.Add(str); } if (arr.Length == 6) { arr[3] = skipurl; arr[4] = title; arr[5] = alt; str = string.Concat(arr[0], "|", arr[1], "|", arr[2], "|", arr[3], "|", arr[4], "|", arr[5]); ls.Add(str); } } } //保存动作 using (System.IO.StreamWriter sw = new System.IO.StreamWriter(string.Concat(ConfigHelper.BaseDirectory, "imagedata.txt"), false)) { foreach (string item in ls) { sw.WriteLine(item); } } }