Peter Chan
asked on
Detect file exist or not
Hi,
I want to check if relevant SpreadsheetDocument is existing or not, per given filepath (having both full path and document name). Only if the file does not exist, then I create it. Otherwise, I just open it. What to adjust below?
I want to check if relevant SpreadsheetDocument is existing or not, per given filepath (having both full path and document name). Only if the file does not exist, then I create it. Otherwise, I just open it. What to adjust below?
public static void CreateSpreadsheetWorkbook(string filepath,string SheetName0)
{
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.
Create(filepath, SpreadsheetDocumentType.Workbook);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try this instead (quick guess):
public static void CreateSpreadsheetWorkbook(string filepath,string SheetName0)
{
if (System.IO.File.Exists(filepath) == false)
{
// Create a spreadsheet document by supplying the filepath.
// By default, AutoSave = true, Editable = true, and Type = xlsx.
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.
Create(filepath, SpreadsheetDocumentType.Workbook);
}
else
{
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(filepath, false);
}
}
ASKER
How to resolve
Open in new window
due to last line below?Open in new window