I have tu publish a windows form application in c#.
The problem is that I have a folder named "dati" in project folder
In code, when I try to read from folder I use this instruction
string projectDirectory = Directory.GetParent(Environment.CurrentDirectory).Parent.FullName;
and when I try to read an xls inside this folder I have this instruction
string path = projectDirectory + "\\dati\\dati.xlsx";
string constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0 Xml;HDR=NO;\"";
In debug all works perfectly, also if I execute the .exe inside bin/Debug or bin/Release folder. When I publish the application, and put it in another folder like C:\ProjectPublished I get this error because it is trying to read the dati folder from another path.
What I have to do? Thanks