@Dineshkumar.S , thanks for the feedback, based on my test, I reproduced your problem.
Because the path will change when you published the app.
You could use the property ApplicationDeployment.IsNetworkDeployed to check if your app has been published by clickonce.
Please refer to the following steps to use the file when your app is published.
First, please create a folder and add the file into the folder, like the following:
Second, please include the txt file in the Application Files:
Third, you could use the following code to call that file:
private void button1_Click(object sender, EventArgs e)
{
if(ApplicationDeployment.IsNetworkDeployed)
{
string path = AppDomain.CurrentDomain.BaseDirectory + @"\Data\1.txt";
string text = File.ReadAllText(path);
MessageBox.Show(text);
}
else
{
string path = Path.Combine(Environment.CurrentDirectory, "..\\..") + @"\Data\1.txt";
string text = File.ReadAllText(path);
MessageBox.Show(text);
}
}
Hope my solution could help you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.