|
@@ -1,5 +1,7 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Diagnostics;
|
|
|
+using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
@@ -13,6 +15,9 @@ namespace PDF_Office.Helper
|
|
|
/// 2 FindVisualChild 查找目标类型的子类控件
|
|
|
/// 3 GetPageParmFromList 从页码集合获取页码字符串,如1,2,3 转换成1-3
|
|
|
/// 4 GetPagesInRange 校验PageRange 输入是否合法,且可返回List<int> Pages 存放的索引值
|
|
|
+ /// 5.ShowFileBrowser 显示系统文件浏览器,可以根据传入的路径参数,自动选中对应的文件
|
|
|
+ /// 6.CreateFilePath 检查对应路径是否有重名,有重名的情况追加尾号
|
|
|
+ /// 7.CreateFolder 检查对应文件夹是否有重名,有重名的情况追加尾号
|
|
|
/// </summary>
|
|
|
public static class CommonHelper
|
|
|
{
|
|
@@ -194,5 +199,83 @@ namespace PDF_Office.Helper
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 显示系统文件浏览器
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="selectedFile">要选中的文件路径</param>
|
|
|
+ public static void ShowFileBrowser(string selectedFile=null)
|
|
|
+ {
|
|
|
+ if(string.IsNullOrEmpty(selectedFile))
|
|
|
+ {
|
|
|
+ Process.Start(@"explorer.exe");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Process.Start(@"explorer.exe", "/select,\"" + selectedFile + "\"");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 检测文件是否重复 追加尾号
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="path"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static string CreateFilePath(string path)
|
|
|
+ {
|
|
|
+ int i = 1;
|
|
|
+ string oldDestName = path;
|
|
|
+ do
|
|
|
+ {
|
|
|
+ if (File.Exists(path))
|
|
|
+ {
|
|
|
+ int lastDot = oldDestName.LastIndexOf('.');
|
|
|
+
|
|
|
+ string fileExtension = string.Empty;
|
|
|
+
|
|
|
+ string fileName = oldDestName;
|
|
|
+
|
|
|
+ if (lastDot > 0)
|
|
|
+ {
|
|
|
+ fileExtension = fileName.Substring(lastDot);
|
|
|
+
|
|
|
+ fileName = fileName.Substring(0, lastDot);
|
|
|
+ }
|
|
|
+
|
|
|
+ path = fileName + string.Format(@"({0})", i) + fileExtension;
|
|
|
+ }
|
|
|
+ ++i;
|
|
|
+
|
|
|
+ } while (File.Exists(path));
|
|
|
+ return path;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 检查文件夹是否重复 追加尾号
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="path"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static string CreateFolder(string folder)
|
|
|
+ {
|
|
|
+ int i = 1;
|
|
|
+ string oldDestName = folder;
|
|
|
+ DirectoryInfo info = new DirectoryInfo(folder);
|
|
|
+ do
|
|
|
+ {
|
|
|
+ info = new DirectoryInfo(folder);
|
|
|
+ if (info.Exists)
|
|
|
+ {
|
|
|
+
|
|
|
+ string fileName = oldDestName;
|
|
|
+
|
|
|
+ folder = fileName + string.Format(@"({0})", i);
|
|
|
+ }
|
|
|
+ ++i;
|
|
|
+
|
|
|
+ } while (info.Exists);
|
|
|
+ info.Create();
|
|
|
+ return folder;
|
|
|
+ }
|
|
|
}
|
|
|
}
|