MarkItUp.SingleUserBlog/Common/FileHelper.cs

(开头部分) 6KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.IO;
using System.Web;
using System.Xml;

namespace MarkItUp.SingleUserBlog.Common {
	public class FileHelper {
		private FileHelper() { }


		public static void ClearFolderContent(string dataFolderPath) {
			try {
				Directory.Delete(dataFolderPath, true);
				EnsureDirectory(dataFolderPath);
			} catch (Exception ex) {
				Console.WriteLine(ex.Message);
			}
		}


		public static void SaveImage(byte[] image, string dataFolderPath, string fileName) {

			fileName = Path.GetFileName(fileName);
			string path = Path.Combine(dataFolderPath, fileName);

            EnsureDirectory(path);

            using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate)) {
				fs.Write(image, 0, image.Length);
			}
		}


		public static string GetUniqueImageName(string dataFolderPath, string fileName) {

			string uniqueName = string.Empty;
			EnsureDirectory(dataFolderPath);

			string fileExtension = System.IO.Path.GetExtension(fileName);
			fileName = Path.GetFileNameWithoutExtension(fileName);

			uniqueName = Path.Combine(dataFolderPath, fileName);
			int i = 1;

			while (File.Exists(uniqueName + fileExtension)) {
				uniqueName = Path.Combine(dataFolderPath, fileName + "_" + i.ToString());
				i++;
			}

			uniqueName += fileExtension;
			uniqueName = Path.GetFileName(uniqueName);
			return uniqueName;
		}


		public static XmlDocument GetDataIndex(string dataFolderPath) {
			string path = Path.Combine(dataFolderPath, "Index.xml");

			XmlDocument doc = new XmlDocument();
			if (File.Exists(path)) {
后面还有 174 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。