David Glover
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,
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,
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.GetDirector yName(Syst em.Reflect ion.Assemb ly.GetExec utingAssem bly().Loca tion)
In my case the path looks like :C:\Users\dglov\AppData\Lo cal\Temp\T emporary ASP.NET Files\vs\c2802a5a\4d0f6b27 \assembly\ dl3\fdbaf9 d4\6e01446 a_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,
System.IO.Path.GetDirector
In my case the path looks like :C:\Users\dglov\AppData\Lo
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
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers 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.
Do you refer to bin\debug or a different folder? In the latter case you need a post-built task to copy it manually.