using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
using (myStream)
{
// Insert code to read the stream here.
System.IO.FileStream fs = new System.IO.FileStream(openFileDialog1.InitialDirectory, System.IO.FileMode.Open, System.IO.FileAccess.Read);
MessageBox.Show("test");
System.IO.StreamReader sr = new System.IO.StreamReader(fs, Encoding.GetEncoding("windows-874")); // อ่านไทยได้
System.IO.FileStream fw = new System.IO.FileStream(output, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
System.IO.StreamWriter sw = new System.IO.StreamWriter(fw);
//Read the first line of text
string line = sr.ReadLine();
//Continue to read until you reach end of file
while (line != null)
{
// if line has 'GL' or 'PP' ignore loop
if ((line.IndexOf("GL") >= 0) || (line.IndexOf("PP") >= 0))
{
line = sr.ReadLine();
continue;
}
//write the lie to console window
sw.WriteLine(line);
//Read the next line
line = sr.ReadLine();
}
sr.Close();
sw.Close();
fs.Close();
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}