1

Basically i have a .net application that has a directory path stored in the app.config file. this directory path outputs xml files that will be read by an asp.net web page.

Is there any way i can get the asp.net web page to read the directory path stored in the app.config file? Should i look to use the web.config file at all?

1
  • Please don't add things like "vb.net asp.net" to your titles. That's what the tags are for. Commented Feb 20, 2012 at 3:18

3 Answers 3

2

The easiest thing to do would be to replicate the directory path into the web.config file of your asp.net web application. You could put the path in the AppSettings element of the web.config file as follows:

<appSettings>
  <add key="FilePath" value="d:\fileDirectory" />
</appSettings>

You can then read this value from your asp.net app using the WebConfigurationManager or the ConfigurationManager. The WebConfigurationManager is the preferred method to use since it know how to handle ASP.Net configuration inheritance (see Antonio's comment below).

You will need to insure that the windows account under which the asp.net process is running has read privileges on the specified directory where the XML files are being stored. You can adjust this using the ACL settings of the directory.

Alternatively, instead of replicating the the directory path in web.config, could try to have your asp.net app directly read the path from the app.config file of your .net app. In this case, you would need to load the contents of the file into an XDocument or use the configuration-parsing tools in .net, and then parse the file to extract the value. You would need to make sure your asp.net app has permissions to read the app.config file. And you would still need to store a path in you web.config, this time to point towhees the app.config file is located. so personally, I would just replicate the path of the xml files into the web.config file of the asp.net app.

Sign up to request clarification or add additional context in comments.

2 Comments

almost +1 ;) for ASP.NET applications it's prefered to use WebConfigurationManager, since it can handle web.config inheritance stackoverflow.com/questions/698157/…
Thanks Antonio for pointing that out. I modified my response post accordingly.
0

To read a app setting from web.xml use
ConfigurationManager under System.Configuration namespace

<appSettings>
    <add key="filepath" value="D:\folder"/>
</appSettings>

To read this setting

ConfigurationManager.AppSettings["filepath"].ToString()

Comments

-1
Dim Xmldoc As New XmlDocument
Dim xmlatt As XmlAttribute
xmldoc.load("your file path")
xmlatt =xmldoc.SelectSingleNode("/configuration/appSettings/add[@key = 'keyname']/@value")

you can use the values as xmlatt.value

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.