将 savedialog 的文件名附加到要保存的文件中
我试图将文件名附加到要保存的文本文件的第一行中。我该怎么做呢?这是代码。我找不到 stringbuilder 在其实例开头附加的方法。
StringBuilder sb = new StringBuilder();
sb.AppendLine("BLAH BLAH");
if (saveFile.ShowDialog() == DialogResult.OK)
{
//How to append file name at the beggining of the file to be saved?
File.WriteAllText(saveFile.FileName, sb.ToString());
}
I am trying to append the name of file in the first line of my text file which is going to be saved. How can I do it? Here is a the code. I couldn't find a method for stringbuilder to append at the beginning of its instance.
StringBuilder sb = new StringBuilder();
sb.AppendLine("BLAH BLAH");
if (saveFile.ShowDialog() == DialogResult.OK)
{
//How to append file name at the beggining of the file to be saved?
File.WriteAllText(saveFile.FileName, sb.ToString());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在调用 WriteAllText 之前添加此行:
-- 或 --
Add this line before you call WriteAllText:
-- or --
要保留以前的文本:
To keep previous text: