Bryan Posted July 30, 2004 Posted July 30, 2004 Ok, I am having trouble accessing an xml file. I have a control that uses a mainMenu.xml file to get the menu structure for a menu. You have to give the control the data source and then bind the data. Well I have this menu on several pages and right now I have to have the mainMenu.xml file in every folder that has a page that access the xml file. What I want to be able to do is keep 1 xml file in my root directory http://localhost/ and not one in each directory. When I set the datasource property to this xml file, what do I need to put for the path? when I use server.mapPath I get something similar to c:\inetpub\wwwroot\AxisFellowship\sermons\lotr\mainMenu.xml The thing is I don't want to have to change the property on each page that uses the menu so it will work once i upload it to my web server. can I use something like Menu1.DataSource = "./mainMenu.xml" Or is there some other way to do this? Quote
jspencer Posted July 30, 2004 Posted July 30, 2004 If you were to put the xml file in the root directory: http://localhost/mainMenu.xml Then if you had pages in http://localhost/Folder1/ Menu1.DataSource would then = "../mainMenu.xml" Then if you had pages in http://localhost/Folder1/Folder2/ Menu1.DataSource would then = "../../mainMenu.xml" Some interesting combinations of folders get a bit trickier, but if you maintain these virtual paths, then moving your pages around stays nice and easy. Hope this answered your question. Quote
Bryan Posted July 31, 2004 Author Posted July 31, 2004 I don't know why this isn't working. I keeping getting errors. I have the file in the root directory: http://www.axisfellowship.org/mainMenu.xml I have the page in http://www.axisfellowship.org/sermons/lotr/index.aspx my datasource code should be: Menu1.DataSource = "../../mainMenu.xml" Is this correct? Quote
Administrators PlausiblyDamp Posted July 31, 2004 Administrators Posted July 31, 2004 Couldn't you store the correct path to the file in the web.config - the control could then read this at runtime. When moving from development to production you would just need to update this one file. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Bryan Posted July 31, 2004 Author Posted July 31, 2004 Couldn't you store the correct path to the file in the web.config - the control could then read this at runtime. When moving from development to production you would just need to update this one file. that sounds like a good idea, but I must admit that I am still learning ASP.net and I don't know how to do that. Could you show me the code I would need to include in the web.config to do this? Thanks Bryan Quote
Administrators PlausiblyDamp Posted August 1, 2004 Administrators Posted August 1, 2004 given the following web.config you shouold be able to read it with code similar to Dim FilePath As String = ConfigurationSettings.AppSettings("PathToFile") not tested this as I don't have VS installed on this machine but it should give you the idea. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Bryan Posted August 1, 2004 Author Posted August 1, 2004 ok, I did that, but now I am getting this error: c:\inetpub\wwwroot\AxisFellowship\default.aspx.vb(26): Value of type 'String' cannot be converted to '1-dimensional array of String'. any ideas? Thanks, Bryan Quote
Bryan Posted August 1, 2004 Author Posted August 1, 2004 given the following web.config <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="PathToFile" value="<enter file path here>" /> </appSettings> </configuration> you shouold be able to read it with code similar to Dim FilePath As String = ConfigurationSettings.AppSettings("PathToFile") not tested this as I don't have VS installed on this machine but it should give you the idea. ok, so I went a slightly different route. instead of the vb code you mentioned I did this: Menu1.DataSource = ConfigurationSettings.AppSettings("MainMenuXMLPath") and it works fine, I don't get the error I mentioned above. Quote
Administrators PlausiblyDamp Posted August 1, 2004 Administrators Posted August 1, 2004 Did you accidently declare your variable as dim FilePath as String() 'or Dim FilePath() as string the top one always catches me out - as it declares an array of strings not a single string. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Bryan Posted August 3, 2004 Author Posted August 3, 2004 Did you accidently declare your variable as dim FilePath as String() 'or Dim FilePath() as string the top one always catches me out - as it declares an array of strings not a single string. that would be the problem. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.