| View previous topic :: View next topic |
| Author |
Message |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Fri Dec 28, 2007 1:05 pm Post subject: [C#] OpenFileDialog help |
|
|
i'v created button and i wanna make him to open an asm file into my TextBox this is my code:
| Code: |
private void OpenClick(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.DefaultExt = "asm";
open.AddExtension = true;
open.FileName = fileName.Text;
open.Filter = "Assembly Files (*.asm)|*.asm||*.extention";
open.FileOk += new CancelEventHandler(openFileOk);
open.ShowDialog();
}
private void openFileOk(object sender, CancelEventArgs e)
{
OpenFileDialog open = (OpenFileDialog)sender;
// need help here... :<
}
|
now i dont know how to continue it... can some1 help me out please?
_________________
Stylo |
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Fri Dec 28, 2007 1:26 pm Post subject: Re: [C#] OpenFileDialog help |
|
|
| 1qaz wrote: | i'v created button and i wanna make him to open an asm file into my TextBox this is my code:
| Code: |
private void OpenClick(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.DefaultExt = "asm";
open.AddExtension = true;
open.FileName = fileName.Text;
open.Filter = "Assembly Files (*.asm)|*.asm||*.extention";
open.FileOk += new CancelEventHandler(openFileOk);
open.ShowDialog();
}
private void openFileOk(object sender, CancelEventArgs e)
{
OpenFileDialog open = (OpenFileDialog)sender;
// need help here... :<
}
|
now i dont know how to continue it... can some1 help me out please? |
Try this:
| Code: |
private void openFileOk(object sender, CancelEventArgs e)
{
OpenFileDialog ofd = (OpenFileDialog)sender;
string FileName = ofd.FileName;
StreamReader sr = StreamReader.null;
try
{
sr = new StreamReader(FileName);
TheCodeTextBox.Text = sr.ReadToEnd(); //I think that's it. I don't remember though; if that isn't it, try what ever's closest
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}
finally
{
sr.Close();
sr.Dispose();
}
}
|
_________________
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Fri Dec 28, 2007 1:46 pm Post subject: |
|
|
Anytime. =)
_________________
|
|
| Back to top |
|
 |
Eyalos Master Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 343
|
Posted: Sat Dec 29, 2007 2:25 am Post subject: |
|
|
| Code: | private void ghey_Click(object sender, System.EventArgs e)
{
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "Choose your executable o-o";
fdlg.InitialDirectory = @"D:\";
fdlg.Filter = "exe files (*.exe)|*.exe|exe files (*.exe)|*.exe";
fdlg.FilterIndex = 2;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
YourText.Text = fdlg.FileName;
}
} |
Wouldnt this be easier?
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Dec 29, 2007 9:42 am Post subject: |
|
|
OpenFileDialog returns a DialogResult?
I thought it returned void. If it does return a DialogResult, then yeah, that would definately be easier.
_________________
|
|
| Back to top |
|
 |
|