将保存saveialog的文件名附加到该文件

|| 我试图在要保存的文本文件的第一行中附加文件名。我该怎么做?这是一个代码。我找不到为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());
}
谢谢。     
已邀请:
在调用WriteAllText之前添加以下行:
sb.Insert(0, saveFile.FileName + Environment.NewLine);
- 要么 -
string outString = saveFile.FileName + Environment.NewLine + sb.ToString();  
File.WriteAllText(saveFile.FileName, outString);
    
要保留以前的文字:
StringBuilder sb = new StringBuilder();

// Appending string to your StringBuilder string value.
sb.AppendLine(\"BLAH BLAH\");

if (saveFile.ShowDialog() == DialogResult.OK)
{
    // Keep the previous file text .. By inserting it in the begining of the 
    // StringBuilder string value. 
    sb.Insert(0, File.ReadAllText(saveFile.FileName) + Environment.NewLine);

    // Insert File Name in the begining of the StringBuilder string value.
    sb.Insert(0, saveFile.FileName + Environment.NewLine);

    File.WriteAllText(saveFile.FileName, sb.ToString());
}
    

要回复问题请先登录注册