locked
How Do I Share Properties Between Two Projects RRS feed

  • Question

  • I have one solution with two projects in it.

    Project One is a Windows form with properties that the form can configure and save. 
    1 using System;  
    2 using System.Collections.Generic;  
    3 using System.ComponentModel;  
    4 using System.Data;  
    5 using System.Drawing;  
    6 using System.Linq;  
    7 using System.Text;  
    8 using System.Windows.Forms;  
    9  
    10 namespace Alliance_Monitor_Configuration  
    11 {  
    12     public partial class Form1 : Form  
    13     {  
    14         public Form1()  
    15         {  
    16             InitializeComponent();  
    17         }  
    18  
    19         private void Form1_Load(object sender, EventArgs e)  
    20         {  
    21             this.SMTPServer.Text = Properties.Settings.Default.SMTP;  
    22  
    23         }  
    24  
    25         private void SaveButton_Click(object sender, EventArgs e)  
    26         {  
    27             Properties.Settings.Default.SMTP = this.SMTPServer.Text;  
    28  
    29             Properties.Settings.Default.Save();  
    30         }  
    31  
    32         private void ResetButton_Click(object sender, EventArgs e)  
    33         {  
    34             this.SMTPServer.Text = Properties.Settings.Default.SMTP;  
    35         }  
    36  
    37         private void button1_Click(object sender, EventArgs e)  
    38         {  
    39             Application.Exit();  
    40         }  
    41  
    42     }  
    43 }  
    44  

    Project two is a Console application that I want to read the Properties from the form project. This is not happening. Basicly any setting I set in the Form project is not shown in the console project when I compile and run.
    1 using System;  
    2 using System.Collections.Generic;  
    3 using System.Linq;  
    4 using System.Text;  
    5  
    6 namespace Alliance_Monitor  
    7 {  
    8     class Program  
    9     {  
    10         static void Main(string[] args)  
    11         {  
    12             Alliance_Monitor_Configuration.Properties.Settings.Default.Reload();  
    13             Console.WriteLine(Alliance_Monitor_Configuration.Properties.Settings.Default.SMTP);  
    14             Console.ReadLine();  
    15         }  
    16     }  
    17 }  
    18  

    Is what I am wanting to do possible and if so how? Or is there another direction I should be going? Any advice/help would be greatly appreciated. Please also note that this is my first C# attempt so I am very new to this :-)
    Thursday, February 5, 2009 6:01 PM

Answers

All replies

  • I don't know what it is that you are doing, but the 2 projects will probably never share a properties folder or files.  What you could do is have the 2 projects use a common file.   The common file could even have strings that point to other files.  XML is very good for doing this sort of thing.

    Rudedog   =8^D
    Mark the best replies as answers. "Fooling computers since 1971."
    Thursday, February 5, 2009 7:04 PM
  • Rudedog2 said:

    I don't know what it is that you are doing, but the 2 projects will probably never share a properties folder or files.  What you could do is have the 2 projects use a common file.   The common file could even have strings that point to other files.  XML is very good for doing this sort of thing.

    Rudedog   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."



    Do you mind pointing me in the direction of doing a common file between the 2 projects. Like I stated I have 0 experience at this point.
    Thursday, February 5, 2009 7:39 PM
  • flyingeagle855 said:

    My idea is to be able to have a gui to set Properties for the console app to use.



    Doesn't sound feasible to me.  Most likely, there is more to it than simply modifying, reading, and writing one single file.  No doubt there are versioning properties associated with the files.
    Mark the best replies as answers. "Fooling computers since 1971."
    Thursday, February 5, 2009 7:40 PM
  • Lookup XML in your Help or the MSDN library.  Here's a thread that shows a clear way to write a class toXML.

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/fda1a06d-f1b3-4430-bc0d-341d68f96490/
    Mark the best replies as answers. "Fooling computers since 1971."
    • Marked as answer by flyingeagle855 Monday, February 9, 2009 11:08 PM
    Thursday, February 5, 2009 7:43 PM
  • RD is right, you cannot share setting files between different applications.  They are strictly isolated from each other.  Since you are saving a simple string, you could use System.IO.File.WriteAllText() to save it, ReadAllText() to read it back.
    Hans Passant.
    • Marked as answer by flyingeagle855 Monday, February 9, 2009 11:08 PM
    Friday, February 6, 2009 3:14 AM
    Moderator