WPF将DataGrid内容保存成文本

目的:将DataGrid里的内容保存成文本。

    以下是datagrid里的内容,欲将其保存成txt文本。

  •  代码如下
FileInfo newFile = new FileInfo(file_path);
if (newFile.Exists)
{
    newFile.Delete();
    newFile = new FileInfo(file_path);
}
using (StreamWriter sw = new StreamWriter(file_path))
{
    for (int i = 0; i < Result_List.Count; i++)
    {
        sw.WriteLine(Result_List[i].FileName);
    }
    if (File.Exists(file_path))
    {
        vm.SbInformation = "文件保存成功!";
    }
}
  • 保存结果

猜你喜欢

转载自blog.csdn.net/u012366767/article/details/81536510
今日推荐