narrator 0 Posted March 24, 2011 Report Share Posted March 24, 2011 Hi,On my site, categories are organized into folders. When there's no body to the page, I use a standard body ( ../inc/body.inc). If there is a body.inc in the same folder, I want it to use that instead. I created the following code for that purpose, but regardless whether there is a body.inc file within the same folder or not, it only uses my standard body file (../inc/body.inc). What's wrong with the code? I've tried changing "body.inc" in lines 3 and 4 to "./body.inc" and ".\body.inc", neither of which makes any difference. I got the basis for the code from here.<%Set fs=Server.CreateObject("Scripting.FileSystemObject")If (fs.FileExists("body.inc"))=true ThenSet f=fs.OpenTextFile(Server.MapPath("body.inc"), 1)Response.Write(f.ReadAll)f.CloseElseSet f=fs.OpenTextFile(Server.MapPath("../inc/body.inc"), 1)Response.Write(f.ReadAll)f.CloseEnd IfSet f=Nothingset fs=nothing%>Thanks,Cheers Quote Link to post Share on other sites
justsomeguy 1,135 Posted March 24, 2011 Report Share Posted March 24, 2011 Use Server.MapPath when you're checking the filename, not just when you open it. Quote Link to post Share on other sites
narrator 0 Posted March 24, 2011 Author Report Share Posted March 24, 2011 Use Server.MapPath when you're checking the filename, not just when you open it.Woohoo!! Thank You.. it works now. <%Set fs=Server.CreateObject("Scripting.FileSystemObject")If (fs.FileExists(Server.MapPath("body.inc")))=true ThenSet f=fs.OpenTextFile(Server.MapPath("body.inc"), 1)Response.Write(f.ReadAll)f.CloseElseSet f=fs.OpenTextFile(Server.MapPath("../inc/body.inc"), 1)Response.Write(f.ReadAll)f.CloseEnd IfSet f=Nothingset fs=nothing%> Quote Link to post Share on other sites
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.