PDA

View Full Version : سوال: اطلاعات چند فایل با هم



shadidayan
جمعه 06 دی 1387, 21:38 عصر
با سلام
می خواهم اطلاعات چند فایل با هم را در یک textboc نشان دهم ولی فقط اطلاعات یکی از آنها را به من نشان می دهد.لطفا کمک کنید



string str;
int len;
Stream myStream;
// OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog2.ShowDialog() == DialogResult.OK)
{
foreach (string fileName in openFileDialog2.FileNames)
{

if ((myStream = openFileDialog2.OpenFile()) != null)
{
// Insert code to read the stream here.
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader(myStream))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
if (line.Contains("TEL") == true)
{
len = line.Length - 1;
str = line.Substring(4, len - 3);
textBox1.Text = textBox1.Text+ "- " + str;
}
else if (line.Contains("Date") == true)
{
len = line.Length - 1;
str = line.Substring(5, len - 4);
textBox1.Text = textBox1.Text +" "+ str;
line = sr.ReadLine();
textBox1.Text = textBox1.Text + "\r\n" + line;
}


//textBox1.Text = textBox1.Text + "\r\n" + line;
}
}
}
catch (Exception err)
{
// Let the user know what went wrong.
MessageBox.Show(err.Message);
}
myStream.Close();
}

}//if1
}

mohsen_csharp
شنبه 07 دی 1387, 10:35 صبح
چون دستور openFileDialog2.OpenFile() هر دفعه فایل اولی رو که انتخاب شده رو باز می کنه
به جای

using (StreamReader sr = newStreamReader(myStream))
اینجوری بنویس



using (StreamReader sr = new StreamReader(fileName))