473,563 Members | 2,668 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.xm l". Now I want to
replace "C:\test.xm l" with the file that the user has chosen by
right-clicking.

The code for the static file is:

private void MainForm_Load(o bject sender, System.EventArg s e)
{
Stream myStream = File.OpenRead(" C:\\test.xml");

XmlSerializer s = new XmlSerializer (typeof(storage ));
objstorage = (storage)s.Dese rialize(myStrea m);

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 1173
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.Com mandLine.

Marc
Sep 7 '07 #2

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

Similar topics

8
1780
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") MyFile.write("This is a test.") MyFile.close() However, using: MyFile = open("MyFile.txt", "w")
5
3547
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. 1 I use for reading, the other for writing. If I write to position 125 on the write_FD, call flush, and then turn around and read from the read_FD...
3
34494
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, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); I get the following exception:
1
1741
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 MyLog.txt file that may be opened (reading and/or writing) by several handles. The Final state I'm looking for is an archive file...
14
19717
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
6269
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 used by another process. But I can open this file fine with Notepad and see the contents. How can I open the file without trying to get a lock on...
1
3593
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 problem as that already works, the trouble is reading the file and writing it back. At the moment, I'm just trying to read it, and write it back and...
6
1657
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 & converting them to an integer. Once the characters are converted to an integer, I'd like to write the data to another file. Here's the code...
16
2209
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 **************************************************************** pair_status/myPair
1
2250
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, according to python's documentation. However, it appears to open the file for reading and appending instead. Is there any way I can open the file for...
0
7659
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7580
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7882
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7634
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7945
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5481
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2079
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
916
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.