My.Settings magic

  • Thread starter Thread starter Bob Altman
  • Start date Start date
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
 
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
 
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.
 
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.
 
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?
 
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
 
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.
 
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
 
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.
 
Back
Top