Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / January 2006

Tip: Looking for answers? Try searching our database.

properties.settings from other project

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SimonV - 09 Jan 2006 16:07 GMT
Hi,
How can I use a connectionstring (or an other setting) that's set in an
other project in the same solution? I've already referenced the other
project .Properties, but that doesn't seem to be sufficent.
I'm using c# 2005
Jesús López - 09 Jan 2006 17:36 GMT
You cannot access settings from another project directly because the class
Settings is declared as internal. However you can write a wapper like this:

Given a class library project called "Library":

namespace Library
{
public class LibrarySettings
{
 public object this[string property]
 {
  get
  {
   return Properties.Settings.Default[property];
  }
  set
  {
   Properties.Settings.Default[property] = value;
  }
 }
}
}

To make the settings to work in a multiproject solution, you must merge the
app.config files into the app.config file of the executable project.

Suppose your executable project is WinApp (a windows application). The
app.config file for WinApp should look like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <configSections>
       <sectionGroup name="userSettings"
type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" >
           <section name="WinApp.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
  <section name="Library.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
 </sectionGroup>
   </configSections>
   <userSettings>
       <WinApp.Properties.Settings>
           <setting name="FormTitle" serializeAs="String">
               <value>Form1</value>
           </setting>
       </WinApp.Properties.Settings>
 <Library.Properties.Settings>
  <setting name="Setting1" serializeAs="String">
   <value>SomeValue</value>
  </setting>
 </Library.Properties.Settings>

</userSettings>
<connectionStrings>
 <add name="Library.Properties.Settings.ConnectionString1"
connectionString="Data Source=(local);Initial Catalog=Norhtwind;Integrated
Security=True"
           providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>

I tested this in a form, and it works:

 private void button1_Click(object sender, EventArgs e)
 {
  Library.LibrarySettings settings = new Library.LibrarySettings();
  MessageBox.Show(settings["ConnectionString1"].ToString());
 }

This aproach is very owfull, however I have not found another more ellegant,
sorry. If someone have a more ellegant aproach, please let me know.

Regards from Madrid (Spain)

Jesús López
VB MVP

> Hi,
> How can I use a connectionstring (or an other setting) that's set in an
> other project in the same solution? I've already referenced the other
> project .Properties, but that doesn't seem to be sufficent.
> I'm using c# 2005
SimonV - 10 Jan 2006 16:06 GMT
Hmm, strange:
When I create a windows project, an other class project can read the
windows project connectionString (not a string setting).
But when I create a VSTO project and I add an connectionString. The
class project can't find that connectionString.
How does this come?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.