| .NET DotNet Forum Index » VB.NET Forum (Visual Basic .NET) » My.Settings magic... |
|
Page 1 of 1 |
|
| Author |
Message |
| Bob Altman... |
Posted: Tue Oct 27, 2009 1:52 pm |
|
|
|
Guest
|
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 |
|
|
| Back to top |
|
|
|
| Joe Cool... |
Posted: Tue Oct 27, 2009 1:52 pm |
|
|
|
Guest
|
On Oct 27, 3:52 pm, "Bob Altman" <r... at (no spam) nospam.nospam> wrote:
Quote: 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. |
|
|
| Back to top |
|
|
|
| Scott M.... |
Posted: Tue Oct 27, 2009 2:32 pm |
|
|
|
Guest
|
"Bob Altman" <rda at (no spam) nospam.nospam> wrote in message
news:%23ajHH8zVKHA.5368 at (no spam) TK2MSFTNGP02.phx.gbl...
Quote: 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 |
|
|
| Back to top |
|
|
|
| Family Tree Mike... |
Posted: Tue Oct 27, 2009 2:56 pm |
|
|
|
Guest
|
Bob Altman wrote:
Quote: 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.
--
Mike |
|
|
| Back to top |
|
|
|
| Family Tree Mike... |
Posted: Tue Oct 27, 2009 3:10 pm |
|
|
|
Guest
|
Joe Cool wrote:
Quote: On Oct 27, 3:52 pm, "Bob Altman" <r... at (no spam) nospam.nospam> wrote:
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.
Where did C# come into this?
--
Mike |
|
|
| Back to top |
|
|
|
| Bob Altman... |
Posted: Tue Oct 27, 2009 3:39 pm |
|
|
|
Guest
|
Quote: 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 |
|
|
| Back to top |
|
|
|
| AMercer... |
Posted: Tue Oct 27, 2009 5:39 pm |
|
|
|
Guest
|
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.
"Bob Altman" wrote:
Quote: 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
.
|
|
|
| Back to top |
|
|
|
| Scott M.... |
Posted: Tue Oct 27, 2009 5:40 pm |
|
|
|
Guest
|
"Joe Cool" <joecool1969 at (no spam) live.com> wrote in message
news:fc9bd3b9-9163-4b45-994c-24a437ff4e39 at (no spam) o10g2000yqa.googlegroups.com...
Quote: 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 |
|
|
| Back to top |
|
|
|
| Bob Altman... |
Posted: Tue Oct 27, 2009 6:26 pm |
|
|
|
Guest
|
"AMercer" <AMercer at (no spam) discussions.microsoft.com> wrote in message
news:AC3F6619-52EC-4385-B318-8F6F9236A5FD at (no spam) microsoft.com...
Quote: 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 to top |
|
|
|
|