how can I modify it to use an OpenFileDialog instead?
Use the dialog to get the Excel file name and alter the connection
string to represent that file instead. What you have:
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data
Source=C:\\TemplateExcel.xls;Extended Properties=Excel 8.0;";
Instead, use something like:
//You should know how to get file name, so this is to save typing
string filePathFromOpenFileDialog = GetFileName();
string template =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={filePath};";
string connectionString = template.Replace("{filePath}",
filePathFromOpenFileDialog);
As long as you check to make sure the file is excel before passing and
add exception handling in case the user picks an Excel file that is not
the right format, you should be fine.
Peace and Grace,
--
Gregory A. Beamer (MVP)
Twitter: @gbworld
Blog:
http://gregorybeamer.spaces.live.com
*******************************************
| Think outside the box! |
*******************************************