我正在尝试创建以下内容。如何阅读文本的特定行并将其显示在消息框中
我的应用程序是Windows应用程序和形式包含以下
- 两个文本框一个名字,另一个用于评论
- 日期时间选择器
- 设置和重置按钮。
现在我的应用程序需要像下面一样工作。
当我打开我的应用程序时,它需要向我显示提醒abt评论和名称谁发表评论指定日期的消息。
为此我不使用任何DataBase我创建的文件来存储注释和名称和日期。
所以我的问题是我应该如何阅读文本区分名称,评论和日期。
我的代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace DateUpdater.Classes
{
public class FileHandling
{
public bool WritetoFile(Classes.FileParameters Params)
{
string directoryPath = Environment.CurrentDirectory.ToString();
directoryPath = directoryPath.ToLower().Replace("\\bin\\debug", "\\Logs\\reminder.txt");
File.AppendAllText(directoryPath, Params.Comments.ToString());
File.AppendAllText(directoryPath, EndCharacter());
File.AppendAllText(directoryPath, Params.Name.ToString());
File.AppendAllText(directoryPath, EndCharacter());
File.AppendAllText(directoryPath, Params.DateToSet.ToString());
File.AppendAllText(directoryPath, EndCharacter());
return true;
}
public Classes.FileParameters ReadFromFile()
{
Classes.FileParameters Params;
string directoryPath = Environment.CurrentDirectory.ToString();
directoryPath = directoryPath.ToLower().Replace("\\bin\\debug", "\\Logs\\reminder.txt");
// string tempData= File.ReadAllText(directoryPath);
var searchTarget = "/n";
foreach (var line in File.ReadLines(directoryPath))
{
if (line.Contains(searchTarget))
{
break; // then stop
}
}
return null;
}
public string EndCharacter()
{
return "/n";
}
}
}
请给我的解决方案...
可以显示在reminder.txt – Dinash 2011-04-25 07:46:25