Open with, file reading

W

walter hausser

Hi everyone!

I have the following problem:
My program saves data as .xml files. I want the following: When a user
right-clicks on a .xml file (in Windows XP), and he chooses "Open
with..." and then he chooses my program, the program should load itself
and should open exactly this x.xml file.

Up to now, I have only a static version; i.e. the method MainForm_load
opens every time the same file, e.g. "C:\test.xml". Now I want to
replace "C:\test.xml" with the file that the user has chosen by
right-clicking.

The code for the static file is:

private void MainForm_Load(object sender, System.EventArgs e)
{
Stream myStream = File.OpenRead("C:\\test.xml");

XmlSerializer s = new XmlSerializer (typeof(storage));
objstorage = (storage)s.Deserialize(myStream);

myStream.Close();
}


PS: Just for clarity one more time: Of course there is an option to
select and open xml files inside the program. But for this, you have
first to run the program. (Also, you don't need to run Winamp first, and
then you can open a mp3 file; but you can simply double-click on the
desired mp3 file.)

I hope you are able to help me.
Thanks


Walter
 
M

Marc Gravell

Such things are typically sent as a command-line argument, i.e.
"my.exe some.file", and you can pick these up from the arguments in
your Main(string[] args) method, or by querying
Environment.CommandLine.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top