목표: File을 생성하거나 파일 내용을 읽어오는 코딩을 해보자.
using System.IO;
1. File Read 작업순서:
/// 파일을 읽어서 richtxt에 보여준다.
/// FuncName: btnSummaryView_Click
/// review : This function is view after read the Summary file
/// apply : file access method,
/// ////////////////////////////////////////////////////////////
private void btnSummaryView_Click(object sender, EventArgs e)
{
if (m_bOpenfile != true)
{
MessageBox.Show("It is not set to see the Summary file!");
return;
}
//richtxtSummaryView.LoadFile(axDBS.strFilePath);
// Read the summary files
string strOneLine = null, strTotalLine = null;
try
{
FileStream aFile = new FileStream(axDBS.strFilePath, FileMode.Open);
StreamReader sr = new StreamReader(aFile);
strOneLine = sr.ReadLine();
// Read the One line from the opened this file.
while (strOneLine != null)
{
strTotalLine += strOneLine + "\r\n";
strOneLine = sr.ReadLine();
}
sr.Close();
richtxtSummaryView.Text = strTotalLine;
}
catch (IOException err)
{
MessageBox.Show(err.ToString());
return;
}
}
2. File Write 작업순서
/// FuncName: btnSummarySave_Click
/// review : This function is view after read the Summary file
/// apply : file access method,
/// ///////////////////////////////////////////////////////////////
private void btnSummarySave_Click(object sender, EventArgs e)
{
if (m_bOpenfile != true)
{
MessageBox.Show("It is not set to see the Summary file!");
return;
}
if (richtxtSummaryView.Text == "")
{
MessageBox.Show("Context of the Summary File is not exist!");
return;
}
FileStream aFile = new FileStream(axDBS.strFilePath, FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(aFile);
sw.Write(richtxtSummaryView.Text);
sw.Close();
}
'프로그래밍 > .Net' 카테고리의 다른 글
class를 만들어 보자 (0) | 2014.01.17 |
---|---|
To execut the another Form(form dialog를 띄워보자) (0) | 2014.01.17 |
OpenFileDialog 사용하기.(OpenFileDlg) (0) | 2014.01.17 |
SourceGrid2 사용하기 (0) | 2014.01.17 |
버튼에 이미지를 넣어서 마우스 포인트 이동시 변환되도록 (0) | 2014.01.17 |