|
@@ -47,9 +47,13 @@ namespace UAS_LabelMachine
|
|
|
ms = DataTableToExcel2(firstsdt, dt, Type, FileName, PageSize, conditionbox);
|
|
|
|
|
|
string filePath = @FolderPath + "\\" + FileName + ".xls";
|
|
|
- if (File.Exists(filePath))
|
|
|
+ int counter = 1;
|
|
|
+ string filename = FileName + ".xls";
|
|
|
+ while (File.Exists(filePath))
|
|
|
{
|
|
|
- filePath = @FolderPath + "\\" + FileName + "(1)" + ".xls";
|
|
|
+ filename = string.Format("{0}({1}){2}", FileName, counter, ".xls");
|
|
|
+ filePath = Path.Combine(FolderPath, filename);
|
|
|
+ counter++;
|
|
|
}
|
|
|
FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
|
|
|
byte[] data = ms.ToArray();
|
|
@@ -71,9 +75,12 @@ namespace UAS_LabelMachine
|
|
|
ms = DataTableToExcel1(firstsdt, dt, Type, FileName, PageSize, conditionbox);
|
|
|
|
|
|
string filePath = @FolderPath + "\\" + FileName + ".xls";
|
|
|
- if (File.Exists(filePath))
|
|
|
- {
|
|
|
- filePath = @FolderPath + "\\" + FileName + "(1)" + ".xls";
|
|
|
+ int counter = 1;
|
|
|
+ string filename = FileName + ".xls";
|
|
|
+ while (File.Exists(filePath)) {
|
|
|
+ filename = string.Format("{0}({1}){2}", FileName , counter, ".xls");
|
|
|
+ filePath = Path.Combine(FolderPath, filename);
|
|
|
+ counter++;
|
|
|
}
|
|
|
FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
|
|
|
byte[] data = ms.ToArray();
|