locked
Checking if excel file exists before opening RRS feed

  • Question

  • I'm writing a program in C# that will open and manipulate an excel file.  However, I will need to check if the file exists BEFORE I attempt to open it.  Here is what I have...

     

    Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();

    xlApp.Visible = false;

    Workbook wb = xlApp.Workbooks.Add(@"C:\test.xls");

     

    How can I check to see if text.xls exists before I open it?

     

    Thanks :)

    Sunday, October 29, 2006 10:39 PM

Answers

  • Hi,

    try using File object's Exists method:

    if (!System.IO.File.Exists(@"C:\test.xls"))
    {
       
    MessageBox.Show("File doesn't exist.");
       
    return;
    }

    Andrej

    Sunday, October 29, 2006 10:43 PM

All replies

  • Hi,

    try using File object's Exists method:

    if (!System.IO.File.Exists(@"C:\test.xls"))
    {
       
    MessageBox.Show("File doesn't exist.");
       
    return;
    }

    Andrej

    Sunday, October 29, 2006 10:43 PM
  • BINGO!

     

    thanks

    Sunday, October 29, 2006 10:57 PM
  • How to use this script to check the existence of file in office 365 SharePoint Online?
    Friday, January 5, 2018 9:18 AM