I'm trying to set up a button to easily export the database in my app to an excel sheet. However I'm having issues getting it to work. And I cant figure out what's going wrong, since I'm not seeing any errors.
{
string cs = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database1.mdf";
SqlConnection con = new SqlConnection(cs);
con.Open();
SqlCommand command = new SqlCommand("SELECT * FROM AvSites", con);
SqlDataAdapter dataadpter = new SqlDataAdapter(command);
DataTable datatable = new DataTable("AvSites");
dataadpter.Fill(datatable);
datatable.WriteXml(Application.StartupPath + "AvSitesDbExport.xlsx");
MessageBox.Show("export data");
}
When I run the app in debug mode, the button creates a xml (xlsx) file on my desktop, which I guess is okay ? since its in debug mode, not sure what rules apply here.
But if I publish the app, I dont see the file being created anywhere.
Am I doing something wrong ? Application.StartupPath should return the dir from which the .exe is executed, right ?