Reputation: 71
I'm trying to develop an application in Win-Forms with a local database which stores product names and prices.
I made a SearchBox
and DataGridView
for displaying products and a WebBrowser
to display HTML files. This shows the product characteristics whenever the user clicks on the product through the DataGridView
. I was thinking to store HTML files in a folder under resources in Visual Studio.
My problem is where will these HTML files be placed after installation by the user (both on x86 and x64 bits)? Because I need to point to the file directory each time the user clicks on a product in the grid view. so here is the code for this
public void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
string Product_id;
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
RCP_id = row.Cells["ProductID"].Value.ToString();
try
{
Browser1.Navigate("file:///C:/Users/ME/Documents/" + Product_id + ".html");
catch
{
RCPBrowser.Navigate("file:///C:/Users/ME/Documents/default.html");
}
}
Upvotes: 2
Views: 935
Reputation: 752
The Ideal way is to place the file in the application folder.
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "//Filename.filetype");
Upvotes: 1
Reputation: 4249
when you put some resources within a Visual Studio project, the default is that the resource is included within the generated executable (exe or dll). You can access them from code using Resources.nameOfTheResource. No other file will be saved on the file system, so your problem is not actually a problem.
But in your case, storing HTML files as resources within the exe is not a good choice: you will not be able to let the browser navigate from one HTML to another.
Store the HTML files is currentExeFolder /Resources (or whatever folder name is appropriate) and deploy them together with your exe.
Upvotes: 1