C# 如何使这组代码将用户输入保存到另一个文件夹中?

C# 如何使这组代码将用户输入保存到另一个文件夹中?,c#,save,user-input,C#,Save,User Input,我太迷路了。。。。如何使这组代码将用户输入保存到另一个文件夹中?(如果您需要知道,我正在尝试保存.png文件) 您还需要编写一些其他和/或附加代码,例如,如果用户从一个文件夹中选择一个文件,那么您可以使用System.IO捕获该文件路径,并查看如何使用GetFilePath、FileName等。。。一旦选择了他们想要保存的文件,为什么不使用file.Copy()方法呢。SO网站上还有很多其他的例子 if (saveFileDialog1.ShowDialog() == DialogResult.

我太迷路了。。。。如何使这组代码将用户输入保存到另一个文件夹中?(如果您需要知道,我正在尝试保存.png文件)


您还需要编写一些其他和/或附加代码,例如,如果用户从一个文件夹中选择一个文件,那么您可以使用System.IO捕获该文件路径,并查看如何使用GetFilePath、FileName等。。。一旦选择了他们想要保存的文件,为什么不使用file.Copy()方法呢。
SO
网站上还有很多其他的例子

if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
    using( Stream myStream  = File.Open(saveFileDialog1.FileName, FileMode.CreateNew))
    using( StreamWriter sw = new TextWriter(myStream) )
    {
        sw.Write("here you can write lines from a file that you read or you can simple write what ever text you are wanting to save to a file this should help you get started" );
    }
}
这里有一个更简单的方法


SaveFileDialog不会为您进行实际保存。您还需要编写一些代码。我将发布一个非常简单的示例,让您尝试将信息存储到变量,然后将该变量写入文件/文件夹。
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
    using( Stream myStream  = File.Open(saveFileDialog1.FileName, FileMode.CreateNew))
    using( StreamWriter sw = new TextWriter(myStream) )
    {
        sw.Write("here you can write lines from a file that you read or you can simple write what ever text you are wanting to save to a file this should help you get started" );
    }
}
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
    System.IO.File.Copy(saveFileDialog1.Filename, "some dest filePath");
}