My.Settings magic

B

Bob Altman

Hi all,

I have a solution that contains two projects: A console app and a Windows
Forms app. The Windows Forms app uses data binding magic to save some
user-supplied data in My.Settings. I would like the console app to be able
to fetch the data from the Windows Forms app's settings. (I know that I
could store the settings someone else, like a file or the registry or
environment variables. Consider this a bit of a science project to see
what's involved.)

I assume that this sort of thing is possible but definitely not for the
faint of heart. If it's going to take a lot of ugly code then I'll just
give up and use some other scheme. But if it's reasonably easy for one
project to read another project's settings then I'd be forever grateful for
an example or description of how to do it.

TIA - Bob
 
S

Scott M.

Bob Altman said:
Hi all,
But if it's reasonably easy for one project to read another project's
settings then I'd be forever grateful for an example or description of how
to do it.

TIA - Bob

I'm not aware of any simple .NET way to do it other than manually reading
the file from the file system. The point of an app.settings file is that it
is to be used from that app, not other ones.

-Scott
 
J

Joe Cool

Hi all,

I have a solution that contains two projects: A console app and a Windows
Forms app.  The Windows Forms app uses data binding magic to save some
user-supplied data in My.Settings.  I would like the console app to be able
to fetch the data from the Windows Forms app's settings.  (I know that I
could store the settings someone else, like a file or the registry or
environment variables.  Consider this a bit of a science project to see
what's involved.)

I assume that this sort of thing is possible but definitely not for the
faint of heart.  If it's going to take a lot of ugly code then I'll just
give up and use some other scheme.  But if it's reasonably easy for one
project to read another project's settings then I'd be forever grateful for
an example or description of how to do it.

TIA - Bob

C#.NET does not know about the VB.NET My object but you can get to the
Settings another way.

Maybe you can do it the same way in a Console app.
 
F

Family Tree Mike

Bob said:
Hi all,

I have a solution that contains two projects: A console app and a Windows
Forms app. The Windows Forms app uses data binding magic to save some
user-supplied data in My.Settings. I would like the console app to be able
to fetch the data from the Windows Forms app's settings. (I know that I
could store the settings someone else, like a file or the registry or
environment variables. Consider this a bit of a science project to see
what's involved.)

I assume that this sort of thing is possible but definitely not for the
faint of heart. If it's going to take a lot of ugly code then I'll just
give up and use some other scheme. But if it's reasonably easy for one
project to read another project's settings then I'd be forever grateful for
an example or description of how to do it.

TIA - Bob

Have you considered creating one application, rather than two? Create a
console app that with a command line switch launches the form, otherwise
just works in command line (console) mode. The single app now has the
access to the single settings.
 
F

Family Tree Mike

Joe said:
C#.NET does not know about the VB.NET My object but you can get to the
Settings another way.

Maybe you can do it the same way in a Console app.

Where did C# come into this?
 
B

Bob Altman

Have you considered creating one application, rather than two? Create a
console app that with a command line switch launches the form, otherwise
just works in command line (console) mode. The single app now has the
access to the single settings.

Thanks, that's just what I needed. I considered creating a single app that
could somehow behave both like a console app and like a Windows Forms app,
but I was trying to do it from the other direction: by creating a Windows
Forms app and trying to make it behave like a console app. But, as you
point out, it should be pretty easy to add the appropriate assembly
references and automatic imports to a console project so that it can put up
a Form.

Bob
 
A

AMercer

You could also create a windows form app whose start object is sub main. It
will behave like a cosole app until it decides to do something with a form,
eg until it does something like
Application.Run(New Form1)
When the form is closed, execution will continue after the .Run() call.
 
S

Scott M.

C#.NET does not know about the VB.NET My object but you can get to the
Settings another way.
Maybe you can do it the same way in a Console app.

Actually, you can use the "My" namespace in C# by referencing the
Microsoft.VisualBasic assembly in the C# app.

-Scott
 
B

Bob Altman

AMercer said:
You could also create a windows form app whose start object is sub main.
It
will behave like a cosole app until it decides to do something with a
form,
eg until it does something like
Application.Run(New Form1)
When the form is closed, execution will continue after the .Run() call.

I considered that approach. The problem is that I want to be able to write
to the output and error streams like a normal console app.
 

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

Similar Threads

My.Settings problem 1
Using My.Settings and forms 4
my.Settings 2
My.Settings.Upgrade doesn't upgrade? 4
My.Settings files 7
My.Settings Questions 31
Encrypt My.Settings setting? 4
My.Settings with roaming profiles 2

Top