473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Probably an easy one for ya - File Associations

I am trying to open an image in a little image viewer I wrote(it has
its own file explorer but I want it to also open from Windows Explorer)
When I select an image from widows explorer and use "Open With"
point it to my app, I can read the args[0] which contains the path to
the file
but I cannot pass the argument to another method to open the image
window

public string thefile = "";

public static void Main(string[] args)
{
Application.Run(new MainForm());
thefile = args[0].ToString();
}

My Documents\SharpDevelop Projects\imgbrowse\MainForm.cs(62,4): error
CS0120: An object reference is required for the nonstatic field,
method, or property 'imgbrowse.MainForm.thefile'

how can I pass the value of args[0] from Main to my ImageView method?

Nov 16 '05 #1
6 1697
Tim Geiges <ke***********@gmail.com> wrote:
I am trying to open an image in a little image viewer I wrote(it has
its own file explorer but I want it to also open from Windows Explorer)
When I select an image from widows explorer and use "Open With"
point it to my app, I can read the args[0] which contains the path to
the file
but I cannot pass the argument to another method to open the image
window

public string thefile = "";

public static void Main(string[] args)
{
Application.Run(new MainForm());
thefile = args[0].ToString();
}

My Documents\SharpDevelop Projects\imgbrowse\MainForm.cs(62,4): error
CS0120: An object reference is required for the nonstatic field,
method, or property 'imgbrowse.MainForm.thefile'

how can I pass the value of args[0] from Main to my ImageView method?


Well, for one thing, Application.Run isn't going to return until your
form has been closed, which probably isn't what you want.

The easiest thing to do would be to make the MainForm constructor take
a string[] parameter, and pass the arguments to that:

[STAThread]
public static void Main(string[] args)
{
Application.Run (new MainForm(args));
}

Then in the constructor, deal with the arguments appropriately.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
OK I see where my problem was, that helped out, Thank you very much
I have one other question, now that I can read the argument properly
my app crashes unless I pass an argument, (I am very new to c# BTW) is
there a way to test args[0] to make sure it exists before trying to set
a string to the value of args[0] hence causing the crash.
if I do

if(args[0] != "") I get an exception
if I set the value of a string to args[0] then do if(mystring != "")
I also get an exception because args[0] does not exist.

Nov 16 '05 #3
args.Length > 0

--
Thanks
Wayne Sepega
Jacksonville, Fl
"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

"Tim Geiges" <ke***********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
OK I see where my problem was, that helped out, Thank you very much
I have one other question, now that I can read the argument properly
my app crashes unless I pass an argument, (I am very new to c# BTW) is
there a way to test args[0] to make sure it exists before trying to set
a string to the value of args[0] hence causing the crash.
if I do

if(args[0] != "") I get an exception
if I set the value of a string to args[0] then do if(mystring != "")
I also get an exception because args[0] does not exist.

Nov 16 '05 #4
Thank You, that was easy :-)

Nov 16 '05 #5
Sorry got another quick one(I think)
when I right click a file (image) and choose "open with" and I browse
for my app, once I select my app it shows up int the "Open With" Dialog
box under "Reccomended Programs" but only the icon there is no
filename or text.
is there a property I need to populate, I have the Text property filled.

Nov 16 '05 #6
Tim Geiges <ke***********@gmail.com> wrote:
Sorry got another quick one(I think)
when I right click a file (image) and choose "open with" and I browse
for my app, once I select my app it shows up int the "Open With" Dialog
box under "Reccomended Programs" but only the icon there is no
filename or text.
is there a property I need to populate, I have the Text property filled.


I don't know what gets used there, I'm afraid.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7

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

Similar topics

1
by: rollasoc | last post by:
Hi, I'm trying to implement file associations with my application. I've been doing this in phases and I'm stuck at the last hurdle. Phases 1) Installer sets up the file association Main in...
4
by: David Allison | last post by:
I am looking to open my MDE Application using the DB files associated with the application I have created. My application is using a non descript three digit extension that is related to the...
1
by: Chance Lerro | last post by:
Here's another way to PREVENT the install program for run-time Access from overwriting existing file associations: 1. Edit the Runtime MSI file with Orca, InstallShield, etc.. 2. Go to the...
2
by: James Reid | last post by:
I'm looking for the source code for a DOS command line c/c++ program that can change file associations. In other words it can cause any version of Windows to associate a particular .exe file with a...
13
by: James Reid | last post by:
I'm looking for the source code for a DOS command line c/c++ program that can change file associations. In other words it can cause any version of Windows to associate a particular .exe file with a...
2
by: Roger Miller | last post by:
When I installed Python 2.5 (on Windows XP) I left 2.4 in place "just in case". Today I decided to remove it. However after doing so (from the control panel) I found that Windows no longer knows...
0
by: Lyle Avery | last post by:
Hi guys, An uninstall of a previous version of Visual Studio, or anything (3rd party dev tools)else happen to unregister these (VS 2005) file extensions. I've tested the ¡°Restore File...
1
by: Lyle Avery | last post by:
Hi guys, Who knows how to restore VS 2k5 file associations, I've clicked Tools->General->"Restore File Associations" button but it doesn't work at all. I know Repair the whole product could fix...
6
by: Jerad Rose | last post by:
I recently installed Visual Studio 2003, after having already installed VS 2005. Unfortunately, it took over all of the file associations. There is an option in Visual Studio 2005 to restore...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...

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.