MainWindow.xaml:
<StackPanel>
<TextBox x:Name="tb" Width="800" Height="100" Background="AliceBlue" />
<Button Click="Button_Click" Content="click"/>
</StackPanel>
MainWindow.xaml.cs:
public partial class MainWindow : Window
{
string path = @"C:\Users\...\WpfApp2\a.txt";
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (File.Exists(path))
{
string projectfolder = "c:\\users\\";
string projectname = "\\0331\\FileOverWriteDemo";
string createText = projectfolder + @"\" + projectname + ".idea";
File.WriteAllText(path, String.Empty);
TextWriter tw = new StreamWriter(path, true);
tw.WriteLine(createText);
tw.Close();
tb.Text = new StreamReader(path).ReadToEnd();
}
}
}
The result:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our [documentation][5] to enable e-mail notifications if you want to receive the related email notification for this thread.
[5]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html