The Jet provider won't work if you're running this code on a 64-bit machine. Jet is 32-bit only.
So, you either have to install the 64-bit ACE engine, downloadable from here[^] or go into your project properties and set the Target CPU to "x86" instead of "AnyCPU". That will force your code to run as a 32-bit application.
I've noticed that when I tried to set a string variable to the folderBrowserDialog.SelectedPath property it does not work. Can someone please explain why that is and is there a way around this? I don't want to have to keep writing folderBrowserDialog.SelectedPath every time I need to use it. Thanks in advance for your reply.
I've noticed that when I tried to set a string variable to the folderBrowserDialog.SelectedPath property it does not work.
"Works on my machine".
Perhaps it'd help if you posted your code? The only way the property (which is a string, an can be assigned to a string-variable) is when the object that owns the property is not yet created. You'd get a refernce-exception.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
The "UnauthorizedAccessException was unhandled" exception was thrown and I get the error message "Access to the path 'C:\MyTestFile' is denied" when I run the code above. It works fine if I use folderBrowserDialog1.SelectedPath in place of myFolderPath.
You can't set string myFolderPath = folderBrowserDialog1.SelectedPath; until after the dialog has returned!
The string there before the call is not modified in place by the dialog.
It is replaced by the dialog. myFolderPath just has the wrong value.
Without seeing the result of the string concatentation you're using inside the parenthsis in the CreateText call, it's impossible to say for sure.
But, if the result is actually a valid path and you're trying to create a file in the root of C: on Vista or Win7, you'll get that error because normal Users cannot create files in the root of C:. You can make folder, not files.
On top of that, why are you calling ToString() on txtFileName.Text?? The .Text property returns a string, so the call to ToString() is a bit redundant.
Thank you everyone for responding. After reading your posts and reexamining my code, I realized that I did make two noob's mistakes. I've fixed the errors and everything works fine. I learned some valuable lessons today and that was the intention of the current project I'm working on. Thanks again for replying.
Any suggestion on how to read Excel file (Xls+Xlsx) without...
a. Excel Interop lib (Microsoft.Office.Interop.Excel) -- as prefer no client side installation
b. OleDB or Jet as in this example[^]...? (As my app 64bit and method via Oledb in the example not compatible)