One way is to pass it as a string:
public void Load(string path)
{
using(StreamReader reader = new StreamReader(path))
{
}
}
[EDIT]
Okay, you want to be able to double click a file and have it open in your program? Well, it sounds like you got the file extension registered to your program, so:
1. In Program.cs add a string array as a parameter to your Main(). This will contain the path to the file you double clicked on.
static void Main ( string[] args )
{
if ( args.Length > 0 )
{
Application.Run( new MainFrm( args[0].Trim() ) );
}
else
{
Application.Run( new MainFrm() );
}
}
2. Overload your program's main form constructor to take a string. This is how you will pass the path from the program's entry point to the form.
public partial class MainForm : Form
{
private string file_path = string.Empty;
public MainForm (){}
public MainForm ( string path )
{
this.file_path = path;
}
}
3. Use the file_path variable to open the file, I would write a separate LoadFile() function that can be called from either the MainForm_Load event handler or anywhere else in your code you might want to load a file from.
public partial class MainForm : Form
{
private string file_path = string.Empty;
public MainForm (){}
public MainForm ( string path )
{
this.file_path = path;
}
private void MainForm_Load ( object sender, EventArgs e )
{
if ( this.file_path != string.Empty )
{
this.LoadFile();
}
}
private void LoadFile()
{
using ( StreamReader reader = new StreamReader ( new FileStream ( this.file_path, FileMode.Open ) ) )
{
}
}
}
[/EDIT]