Last post Mar 31, 2018 06:33 PM by oneillj
Mar 30, 2018 05:22 PM|oneillj|LINK
I was using 2017 and kept getting an error that the page could not load. After trying to publish, I got the same error. I came across a post that says change CodeBehind to CodeFile and got this error....
Could not find file 'D:\hshome\oneillj\jimoneill.us\App_Data\emailList.xml'.
Here is the procedure...
protected void GetData()
string xmlPath = @"~\App_Data\emailList.xml";
string fileName = HttpContext.Current.Server.MapPath(xmlPath);
DataSet ds = new DataSet();
GridView1.DataSource = ds;
Works fine in the IDE and when I bring it up on the local IIS host but I can't get it to run on two different sites. Never had a problem when uploading to intranet IIS servers at work but both hosting sites give me an error.
I don't know why I would have to change the CodeBehind to CodeFile. Seems if it works on my machine, it should work on a live site. I'm not really sure what the difference is between the two keywords.
Mar 30, 2018 06:06 PM|PatriceSc|LINK
Could it be that this file really doesn't exists ? It is perhaps not published and you have also a publish option that allows to ignore what is found in App_Data. Make sure this option is not checked.
Revert back other changes. CodeBehing and CodeFile are two separate compilation models and you should avoid to try random unrelated things. Understand first what happens and fix this.
For now it seems the file really doesn't exists on your host.
Mar 30, 2018 06:19 PM|oneillj|LINK
Yes, the file is there. This version that I got the "file not found" error was not published. I'm sorry if there was any confusion in the original post. When the keyword was CodeBehind, the page would not load at all. When I changed it to CodeFile, the page
did load and I got the error above. I now realize that the CodeFile is set when the option is to create a website while CodeBehind is a web application. I am used to working with 2010 and the original page was built with 2017 Community which does not give
you the option for a Website. Still, I don't understand why the relative path would be wrong on a live site but work on my machine. I would think the Current.Server.MapPath() would be a sure fire way to get to the file.
Mar 31, 2018 09:57 AM|PatriceSc|LINK
"there" but "where" ? I would show Server.MapPath("~/App_Data") to check if it uses the locartion you think as well as
https://msdn.microsoft.com/en-us/library/system.io.directory.getfiles(v=vs.110).aspx to see which files I have.
If a problem is not 100% clear it's always IMO to do this kind of quick check to better narrow down what happens exactly.
Mar 31, 2018 06:33 PM|oneillj|LINK
Ended up changing the path and using the Current.Request.MapPath(fileName);
string xmlPath = "App_Data/emailList.xml";
string fileName = HttpContext.Current.Request.MapPath(xmlPath);