Last post Nov 05, 2010 07:50 AM by skifreak
Nov 03, 2010 02:27 PM|skifreak|LINK
I just created an XML file in my project called EmailAddresses:
<?xml version="1.0" encoding="utf-8" ?>
I want to be able to read that and not by hard coding a path as I don't know where it will be installed when it goes into production.
Any help is greatly appreciated.
Nov 03, 2010 02:32 PM|karan@dotnet|LINK
You need to create a key value in your web.config file, have your path stored there (there has to be one path where your files are stored) and then get this path from config file.
Of this path changes you only need to change the path in config file
Nov 03, 2010 02:36 PM|santa_1975|LINK
Can't you dynamically generate this xml in your project rather than placing it in a folder and doing an I/O operation which is costly?
Nov 03, 2010 03:29 PM|skifreak|LINK
Can you point me to an example on how to put the path in the config and how to use it?
Santa, I cannot do this in code as the email address can change and why would I want to have to compile the entire project just to change an email address? Thanks for your suggestion though.
Nov 03, 2010 03:38 PM|karan@dotnet|LINK
<add key="xmlPath" value="yourxmlpathgoeshere"/>
//Code as how to get this value from web.config
string xmlPath = ConfigurationManager.AppSettings["xmlPath"];
Nov 04, 2010 07:14 AM|skifreak|LINK
The 'yourpathgoeshere' is what I am not sure what to put or how to code it. I have several projects in my solution. UI, BL and DAL and a windows service. The code is in the windows service and the web.config is in the WebApp. Hope this helps you more
in what I am looking for.
Nov 04, 2010 10:53 PM|Decker Dong - MSFT|LINK
Just use LINQ-TO-XML:
string value = XDocument.Load("xxx.xml").Root.Element("To").Value;
Nov 05, 2010 07:50 AM|skifreak|LINK
Exactly what I was looking for. Thanks Decker. Didn't think to use Linq to XML