Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Server.MapPath help

Status
Not open for further replies.

scribbler

MIS
Feb 4, 2002
206
GB
Can anyone please tell me the answer to the following problem ?

I would like to ammend a string to a variable in the following line instead of the actual file name itself. Each time I attempt to do this I get an error and do not know if it is my incorrect syntax that's causing it or whether it just isn't possible to use a variable in this case.


sPath=Server.MapPath("TestFile.asp")

 
Your syntax looks fine. What error are you getting? Turn on friendly error messages in IE if it is not giving you an error code. (Tools >> Internet Options >> Advanced)

Tony
________________________________________________________________________________
 
Hello scribbler,

Further to what advised, if it is syntax of making the argument variable, the only thing to make sure is you pass a string variable (preferrable a valid path)...
[tt]
s="TestFile.asp"
sPath=Server.MapPath(s)
[/tt]
Hoping you did not make it like sPath=Server.MapPath("s").

regards - tsuji
 
I ammended the file name which had worked ok from
sPath=Server.MapPath("TestFile.asp")
To
sPath=Server.MapPath(TestFile)


The error I received was;

Server.MapPath() error 'ASP 0171 : 80004005'

Missing Path

/TestFile.asp, line 42

The Path parameter must be specified for the MapPath method.
 
That isnt quite what tsuji wrote. Unless of course you declared a varible called TestFile and gave it a value of "TestFile.asp".

Try writing it just as in tsuji's example. What error, if any, do you recieve then?

Tony
________________________________________________________________________________
 
In Addition to my previous reply the Enable Parent Paths Tick box is found in the "Home Directory" tab of a websites propeties in IIS then click on the "Configuration" button in application section.

A new dialogue box will appear, select the "App Options" tab and you will see the check box
 
Thanks for the replies but I don't think Ive explained myself or at least given the whole picture so here goes. I know the Request.querystring("Choice")is ok and contains the expected value as it writes the filename to screen using response.write.

Here's my code below with the error at the btm of the page:

'sent Request.querystring("Choice") into variable as it wouldn't work in the server.mappath
chosenitem = Request.querystring("Choice")
'Again chosenitem works ok as it prints the value to screen
Server.MapPath(chosenitem)
sPath = Server.MapPath(chosenitem)
Set oFSO=Server.CreateObject("Scripting.FilesystemObject")





Server.MapPath() error 'ASP 0173 : 80004005'

Invalid Path Character

/ConfirmSendAdvert.asp, line 43

An invalid character was specified in the Path parameter for the MapPath method.
 
This line:
Code:
Server.MapPath(chosenitem)
is a problem because you're not assigning the result of the mapping to anything. This line:
Code:
sPath = Server.MapPath(chosenitem)
is fine. It's no surprise you're getting an error on the first line. Just delete it, since the second line does what you want.
 
Sorry Genimuse I did copy/paste my code onto this page but as it included lots of response.write items that I had written in an attempt to see what's happening, I did remove those lines. Regrettably I left a part of one in, that being the code you spotted. I've taken the lines out again and this is what I'm left with (which I tested again and still doesn't work as it gives me the error at the bottom)

chosenitem = Request.querystring("Choice")
sPath = Server.MapPath(chosenitem)
Set oFSO=Server.CreateObject("Scripting.FilesystemObject")
Set oFile=oFSO.OpenTextFile(sPath)
sOutpUt=oFile.ReadAll



Server.MapPath() error 'ASP 0171 : 80004005'

Missing Path

/ConfirmSendAdvert.asp, line 41

The Path parameter must be specified for the MapPath method.
 
So if you change it to:
Code:
chosenitem = Request.querystring("Choice")
Response.Write("<h3>|" & chosenItem & "|</h3>")
Response.Flush()
sPath = Server.MapPath(chosenitem)
Set oFSO=Server.CreateObject("Scripting.FilesystemObject")
Set oFile=oFSO.OpenTextFile(sPath)
sOutpUt=oFile.ReadAll
what does it show between the pipe characters (|)?
 
Hi Genimuse

This is the reply I received, which is the correct file but still getting an error

|adminstrators.htm|
 
That error message just makes no sense, then. Hmm.

Well, these don't explain the error, but just in case, first, is the administrators.htm file in the same directory as this asp page?

The only other thing is did you ensure that Enable Parent Paths was checked?

Otherwise I have no clue at all.
 
scribbler,

It is most probably illegal characters that cause it.
[tt]
response.write escape(chosenitem)
[/tt]
Does it should nonprintable characters? Or for small string, just check

[tt] response.write len(chosenitem) [/tt]

see if it agrees with your visual counting (of printable characters).

- tsuji
 
I obviously hadn't read the path in full because it started correctly and ended eith my expected filename but the path displayed shows me everything up to and including the directory but then does display the filename which is not quite correct as this file is in a directory off the directory. The site is hosted elsewheres so far as I know I don't have access to IIS settings.

I will also run Tsuji suggestion and let you know what I get in return.
 
After all that effort it seemed that MarkEmmerson's suggestion re: AspEnableParentPaths was part of the problem after I had contacted my the site host. But I did work around it after you guys pointed me in the right direction by adding the actual subdirectory name to the server.MapPath line and this cured it.

This learning lark is damn frustrating. There must be easier ways to achieve things but I'm sorry to say I'm sure I'll be back on with some more problems.

Thanks for your help guys.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top