473,498 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open with, file reading

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
Sep 7 '07 #1
1 1172
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
Sep 7 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1771
by: Peter A. Schott | last post by:
Been reading the docs saying that file should replace open in our code, but this doesn't seem to work: # Open file for writing, write something, close file MyFile = file("MyFile.txt", "w")...
5
3538
by: JG | last post by:
Hi all, Does anyone know how the implementations on Linux and Windows handle synchronization between a read and write FD open to the same file. For example, if I have 2 FD open to file X.txt. ...
3
34466
by: trellow | last post by:
Hello, I am writing an application that needs to read a file that is already open by another process for writing. When I do the following: FileStream fs = new FileStream(fileName,...
1
1734
by: dwainew | last post by:
Problem: I'd like to archive off the contents of a text file. However, other processes may have the file open, so MoveTo(newfilepath) can't be done, as far as I've found. Start with a 5 MB...
14
19680
by: Rochester | last post by:
Hi, I just found out that the general open file mechanism doesn't work for named pipes (fifo). Say I wrote something like this and it simply hangs python: #!/usr/bin/python import os
5
6266
by: MrNobody | last post by:
I was writing a program that was reading data from files (not making any changes) and I used the File.OpenRead(filename) command. It threw an error for one file because it said the file was being...
1
3592
by: piratelord | last post by:
I've an existing program I need to tweak that can open a non-text file at low level, find certain strings and replace with another, and write back to a new file. The string replacement bit isn't a...
6
1653
by: gonzlobo | last post by:
I've been using Python for a few days. It's such the perfect language for parsing data! I really like it so far, but I'm having a hard time reading a file, reading the first few hex characters &...
16
2204
by: Gary Wessle | last post by:
Hi please help with this. std::fstream iofs( f.c_str(), std::ios::in|std::ios::out ); std::cout << f << '\n' << iofs.is_open() << std::endl; puts out...
1
2249
Xx r3negade
by: Xx r3negade | last post by:
Sorry for the extreme newbie question, but I honestly can't find this anywhere else. When I do f = open('/var/www/some_file', 'r+') it is supposed to open the file for reading and writing,...
0
7005
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7210
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6891
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7381
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5465
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4916
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4595
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
293
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.