如何使用Environment.SpecialFolder在Xamarin / VisualStudio项目中指定特定文件?

时间:2018-08-27 16:27:45

标签: c# xamarin streamwriter

我正在尝试将文本添加到文本文件中,但是在任何地方都找不到如何找到现有文件的方法。

 partial void MainBtn_TouchUpInside(UIButton sender)
        {
            var Pp = ("Selected Form Of Exchange: Paypal");
            string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments(WHAT DO I WRITE IN THIS SPACE??);
            using (StreamWriter outputFile = new **StreamWriter(Path.Combine(mydocpath, "SelectPayment.txt")))

//我知道该文件已经存在,我正在尝试其他事情。

            {

                outputFile.WriteLine(Pp);

}

那我该怎么办?谢谢 乔什

1 个答案:

答案 0 :(得分:0)

您通过组合文件夹路径和文件名来创建文件路径来指定文件

// this returns the path to a folder
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));

// combine that with a file name to create a file path
string file = Path.Combine(path, "myFile.text");

// append text to file
File.AppendAllText(file, "this is the text I want to append);