I have used the above source code. It is fine on visual studio but after changed to .exe file the word templete couldn't change the content. I think the path is on the StartupPath so it makes it by default Read Only file.
installation path = C:\Program Files (x86)\Ocean Ict Center\Setup
path on source code =
string samplePath = Application.StartupPath + Path.DirectorySeparatorChar + "Template.docx";
string docxPath = Application.StartupPath + Path.DirectorySeparatorChar + "Result.docx";How it can be solved?
You can also show me how to use Report Viewer with Ms Access database with the source code above.
For more the source file and the description found in the first replay, following the link, copy and paste on you browser:

NURU DAWUD199 reputationPosted Mar 30, 2023, 10:50 AM EDT
copy and paste to get the Source file and the description:
https://www.c-sharpcorner.com/UploadFile/38268a/create-word-document-from-win-form-with-users-data/
Rajkiran SwainRank #165 · 14.4K reputationPosted Apr 13, 2023, 7:46 AM EDT
string reportPath = Application.StartupPath + Path.DirectorySeparatorChar + "MyReport.rdlc"; ReportDataSource reportDataSource = new ReportDataSource("MyDataSource", myDataTable); reportViewer1.LocalReport.DataSources.Clear(); reportViewer1.LocalReport.ReportPath = reportPath; reportViewer1.LocalReport.DataSources.Add(reportDataSource); reportViewer1.RefreshReport();Tuhin PaulRank #7 · 71.9K reputationPosted Apr 15, 2023, 7:25 AM EDT
To solve the issue with the file being read-only in the installation directory, you can try copying the file to a different directory where the user has write permissions, such as the user's Documents folder.
string samplePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Template.docx"); string docxPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Result.docx"); File.Copy("C:\Program Files (x86)\Ocean Ict Center\Setup\Template.docx", samplePath); File.Copy("C:\Program Files (x86)\Ocean Ict Center\Setup\Result.docx", docxPath);Tuhin PaulRank #7 · 71.9K reputationPosted Apr 15, 2023, 7:26 AM EDT
code snippet that shows how to load data into the dataset using an OleDbDataAdapter
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\path\\to\\your\\database.accdb"; string query = "SELECT * FROM Customers"; OleDbConnection connection = new OleDbConnection(connectionString); OleDbDataAdapter adapter = new OleDbDataAdapter(query, connection); DataSet dataSet = new DataSet(); adapter.Fill(dataSet, "Customers"); ReportDataSource reportDataSource = new ReportDataSource("Customers", dataSet.Tables[0]); reportViewer1.LocalReport.DataSources.Clear(); reportViewer1.LocalReport.DataSources.Add(reportDataSource); reportViewer1.RefreshReport();assuming that you have a table named "Customers" in your MS Access database.