asp.net - c# how to give relative path in web.config -
here folder structure
d: |_ myproject | |_web.config |_ sample |_xml-file
in web.config have given absolute path as:
<add key="xmlpath" value=" d:\sample\xml file" />
now, how can change path relative path? tried below , not working.
<add key="xmlpath" value=" ..\..sample\xml-file" />
i have old old code. whenever wanted put relative file-path-name in settings-xml-config, call helper function(s).
public class directoryhelpers { public static string findphysicalrootdirectory(page p) { string rootdir; //rootdir = p.server.mappath("/"); rootdir = p.server.mappath("~/"); return rootdir; } public static string findvirtualrootdirectory(page p) { return "~/"; } }
and example:
public partial class directorycheck : system.web.ui.page { protected void page_load(object sender, eventargs e) { string x = string.concat("physical directory: ", common.directoryhelpers.findphysicalrootdirectory(this.page)); } }
append1:
once have findphysicalrootdirectory, read relative file path web.config , use system.io.path.combine combine 2 values.
Comments
Post a Comment