How do I show a Save As dialog in WPF?

后端 未结 6 2115
鱼传尺愫
鱼传尺愫 2020-12-13 08:46

I have a requirement in WPF/C# to click on a button, gather some data and then put it in a text file that the user can download to their machine. I can get the first half of

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-13 09:00

    Here is some sample code:

    string fileText = "Your output text";
    
    SaveFileDialog dialog = new SaveFileDialog()
    {
        Filter = "Text Files(*.txt)|*.txt|All(*.*)|*"
    };
    
    if (dialog.ShowDialog() == true)
    {
         File.WriteAllText(dialog.FileName, fileText);
    }
    

提交回复
热议问题