0
我无法在文本文件中导出多行文本框内容。无法导出文本框内容C#
它正在创建文件,但没有输入任何值。我可以使用双引号对它进行硬编码,它可以工作,但是在尝试使用文本框本身作为内容时。什么都没有显示。
protected void PrintBtn_Click(object sender, EventArgs e)
{
var ingredients = IngredientsList.Text;
string path = @"C:\Users\Donald\Desktop\Folder\ingredients.txt";
if (!File.Exists(path))
{
// Create a file to write to.
string createText = ingredients + Environment.NewLine;
File.WriteAllText(path, createText);
}
// This text is always added, making the file longer over time
// if it is not deleted.
string appendText = ingredients + Environment.NewLine;
File.AppendAllText(path, appendText);
// Open the file to read from.
string readText = File.ReadAllText(path);
Console.WriteLine(readText);
}
但这会在桌面上创建一个文档,并允许该人保存? –
请注意,默认情况下System.IO未被引用,因此它将是'System.IO.File.WriteAllText' –
path是什么意思? –