Reputation: 145
I want to know is there any way to embedded the email setting in windows application other then storing in app.confg file.The settings will be static so user dont have to change it during run time. As far as i know we can save it on resource file as string ,but how can i access the settings in my code?
Code:
string st = Properties.Resources.cubemail;
//SmtpSection smtpSection = ConfigurationManager.GetSection(st) as SmtpSection;
MailSettingsSectionGroup mMailSettings =
ConfigurationManager.GetSection(st) as MailSettingsSectionGroup;
mail.From = new MailAddress(mMailSettings.Smtp.From);
smtp.Host = mMailSettings.Smtp.Network.Host;
smtp.Port = mMailSettings.Smtp.Network.Port;
smtp.UseDefaultCredentials = mMailSettings.Smtp.Network.DefaultCredentials;
smtp.Credentials = new System.Net.NetworkCredential(
mMailSettings.Smtp.Network.UserName,
mMailSettings.Smtp.Network.Password);
Upvotes: 0
Views: 212
Reputation: 94643
Use XML document to store email-settings where you can open/update XML document in notepad like text editor or read or update using Linq To XML.
EDIT:
If you've mark XML document as embedded resource then you can read it via Assembly.GetManifestResourceStream() method.
I presume that the name of xml document is Test.xml
and is created under root with WindowApp
namespace.
Test.xml
<?xml version="1.0" encoding="utf-8" ?>
<MySettings>
<host>something.com</host>
</MySettings>
To read a resource,
Assembly assembly = Assembly.GetExecutingAssembly();
XDocument doc= XDocument.Load(assembly.GetManifestResourceStream("WindowApp.Test.xml"));
string host=doc.Root.Element("host").Value;
Upvotes: 1
Reputation: 2748
Add xml file in your project and mark that file as embedded resource, you can put all setting there
Upvotes: 1