Link to home
Start Free TrialLog in
Avatar of David Glover
David GloverFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Why does my settings.xml file, stored in my project root, not copy to the output folder?

I have googled this one and despite numerous suggestions I have not succeeded and yet it seems so simple.
In visual studio community 2017 edition, I have a vb web application which includes an XML file of program settings which I do not want to embed, I want it to stay as an .xml file so the site's behavior can be altered without recompilation.
When I run the web application in debug , the output folder shows the web app DLL of the compiled web app and no XML file and the program fails to locate it.
The file is set to Copy to Output directory and I have tried Content, Additional Files, None, to no avail, it never copies.  If I copy the XML file to the output folder whilst in debug mode it works so the question is why does my XML file not copy to the output directory.
I have included the xml file at the top level of the project.  
What needs to happen for the web app to copy the XML file to the temporary debug iis express folder so my website can find it and work?
Thank you,
Avatar of ste5an
ste5an
Flag of Germany image

What is wrong with using web.config?

temporary debug iis express folder
Do you refer to bin\debug or a different folder? In the latter case you need a post-built task to copy it manually.
Avatar of David Glover

ASKER

Hi ste5an, I am using the property below which returns the path where the application seems to be executing from which doesn't contain the xml file.  
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)

In my case the path looks like :C:\Users\dglov\AppData\Local\Temp\Temporary ASP.NET Files\vs\c2802a5a\4d0f6b27\assembly\dl3\fdbaf9d4\6e01446a_976bd401

If I open this path my webpage tries to access the xml file and copy the xml file manually the program works but I have to do this every time I run up debug.

If you think your web.config solution is the right way, can you please point me to an example of copying a file with this method because I am struggling to locate one.
thank you,
Wrong path. E.g. in a ASP.net MVC:

Function About() As ActionResult
    ViewData("Message") = "Your application description page."
    ViewData("Path") = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
    ViewData("ApplicationPath") = HttpContext.Request.ApplicationPath
    ViewData("PhysicalApplicationPath") = HttpContext.Request.PhysicalApplicationPath
    ViewData("PhysicalPath") = HttpContext.Request.PhysicalPath
    Dim xmlPath As String = Path.Combine(HttpContext.Request.PhysicalApplicationPath, "XMLFile1.xml")
    Dim document As XDocument = XDocument.Load(xmlPath)
    ViewData("Document") = document.Root
    Return View()
End Function

Open in new window

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.