0
        xlApp = new Excel.Application();
        xlWorkBook = xlApp.Workbooks.Open("‪‪C:\\Data_check\\Load Data Check_new_3.xlsx", 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", true, false, 0, false, 1, 0);

I am trying to open an excel workbook through the above code, however it throws an error that the file could not be found or is it moved, or removed. I can open the file if i type the path in windows explorer .

The screenshot of the error is shown: Cannot find file I'm not sure what the problem is here.. I was able to open a similar file placed on my desktop but not this one.

4
  • Try to open an other file in an other folder, so you can see if the problem is in your code or has to do with something in your environment (operation system, user rights, ...). Commented May 26, 2016 at 6:52
  • Does System.IO.File.Exists("‪‪C:\\Data_check\\Load Data Check_new_3.xlsx") return true? So we can isolate this as an Excel issue rather than permissions etc? Commented May 26, 2016 at 8:43
  • No , It seems to be returning false.However the file does exist on the path. Any more suggestions? @GodLovesATrier Commented May 26, 2016 at 9:11
  • So it's not excel-specific then. Try using (var fs = System.IO.File.Open("...", FileMode.Open, FileAccess.ReadWrite)); see what exception that raises Commented May 26, 2016 at 9:38

2 Answers 2

1

Your path has empty space, which will cause a problem in opening the file at runtime - Load Data Check_new_3.xlsx

Sign up to request clarification or add additional context in comments.

3 Comments

No, that is incorrect. I was able to open a file with white spaces in its name with the same code. However when i changed the path to this file i can't open the same.
Here the issue is simply file not found, so the program is not able to parse your file path correctly, try removing those spaces and ensure that file name match in the actual folder
As i mentioned above, that is incorrect. I opened a file with white spaces in it's name with the same code, however to recheck i changed my file name without spaces and tried the same, and still it doesn't work. This is not the answer.
1

Try @Mrinal Kamboj answer

Or try shorten the file name by a few characters The full PATH name - drive, folders, filename, cannot exceed 218 chars

6 Comments

Application.StartupPath exists in which namespace?
This is not relevant.
then may be that path/folder is inaccessible. check your path/folder permissions
or try to run your application with administrator previllages
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.