15-05-2009, 07:58
|
|
|
|
חבר מתאריך: 23.12.06
הודעות: 40
|
|
קוד לפתיחת קובץ
היי
לפתיחת קובץ אתה יכול להשתמש בקוד הבא (C#)
private void btnOpenFile_Click(object sender, EventArgs e)
{
txtManualQuery.Enabled = true;
OpenFileDialog ofd = new OpenFileDialog(); //Define object of OpenFileDialog
FileStream strm; //Object "open" file
ofd.Filter = "Text File (*.txt)|*txt| SQL File (*.sql)|*.sql"; //File Type available for Open...
ofd.Title = "Type File";
if (ofd.ShowDialog() == DialogResult.Cancel) //If "Cancel" - event
{
txtManualQuery.Enabled = false;
return;
}
try
{
strm = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read);
StreamReader rdr = new StreamReader(strm);
while (rdr.Peek() >= 0)
{
string str = rdr.ReadLine();
txtManualQuery.Text += str;
}
}
catch (Exception)
{
MessageBox.Show("Error Opening File", "I-Do-Query Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
|