maytawn
asked on
How can I Use Server.MapPath() when the filename has a comma in it?
I'm trying to use the Server.MapPath() method to check for the existance of a certain file. Unfortunately the file that I'm searching for may have a comma in the filename ex <c:\test, test.txt>. I have no control over the filename so I need to find a work around that will allow me to use extract the actual full path of the file.
Currently I get the following error:
Server.MapPath() error 'ASP 0173 : 80004005'
Invalid Path Character
Currently I get the following error:
Server.MapPath() error 'ASP 0173 : 80004005'
Invalid Path Character
Why are you using Server.Mappath when you have the full path anyway? If you pass "C:\test, test.txt" to server.mappath, it probably will cause an error. What you put inside mappath is the virtual file path: Server.Mappath("/directory 1/director y1.1/test, test.txt")
And this will be converted into something like: "C:\InetPub\WWWroot\Server 1\director y1\directo ry1.1\test , test.txt".
And this will be converted into something like: "C:\InetPub\WWWroot\Server
I don't think that throws an error Alpha, it just gives what you give it... I believe he just gave an example, not what he actually did... but if he did. I don't know
I don't think that throws an error Alpha, it just gives what you give it... I believe he just gave an example, not what he actually did... but if he did. I don't know
These are the errors I got with:
Server.MapPath("C:\test, test.txt")
"The Path parameter for the MapPath method must be a virtual path. A physical path was used."
Server.MapPath("test, test.txt")
"An invalid character was specified in the Path parameter for the MapPath method."
Server.MapPath(Server.URLE ncode("tes t, test.txt"))
D:\SERVER-CLIENTS\Bis-Web\ 2-Sites-No t-Hosted-B y-Bis-Web\ A&L_Intran et\_manage ment\test% 2C+test%2E txt
So I guess it works with your example then lxeus?
Server.MapPath("C:\test, test.txt")
"The Path parameter for the MapPath method must be a virtual path. A physical path was used."
Server.MapPath("test, test.txt")
"An invalid character was specified in the Path parameter for the MapPath method."
Server.MapPath(Server.URLE
D:\SERVER-CLIENTS\Bis-Web\
So I guess it works with your example then lxeus?
Can we use Server.MapPath("test" & chr(44) & " test.txt")
?
Dave
?
Dave
I believe Server.Mappath(Server.HTML Encode("te st, text.txt")) would work fine...
did it?
did it?
Server.HTMLEncode is used to preserver characters displatyed in an HTML page from not being interpreted as HTML - ie displaying a less than sign
All the work here is done on the server so I don see how this solves anything
Dave
All the work here is done on the server so I don see how this solves anything
Dave
Believe so Alpha, I use Server.HTMLencode for any field manipulation or parameter passing, simply cos of illegal chars throwing errors...
~Ixeus
~Ixeus
p.s. I think he went to bed...
I think Server.URLencode is the one to use. Surely Server.HTMLEncode would do nothing to "test, test.txt", as there's no illegal characters in there?
Server.URLPathEncode might be the real one to try?
Server.URLPathEncode might be the real one to try?
And maytawn... WAKE UP!!!!
blehhhhhhhhhhhhh what everrrrrr :p
same difference, idea was there
oh well =p
guess yours then
same difference, idea was there
oh well =p
guess yours then
If you have a file at "/work/test, test.txt" you can user Server.MapPath("/") to get the path to the applications root, then add the virtual path. If you have a file at "work/test, test.txt", you can user Server.MapPath(".") to get the path of the current folder, then add the virtual path.
Function GetPath(strFile)
If Left(strFile,1)="/" Then
GetPath=MapPath("/") & strFile
Else
GetPath=MapPath(".") & "\" & strFile
End If
End Function
Function GetPath(strFile)
If Left(strFile,1)="/" Then
GetPath=MapPath("/") & strFile
Else
GetPath=MapPath(".") & "\" & strFile
End If
End Function
...and maybe replace / with \ in the name, if the file system is picky...
Function GetPath(ByVal strFile)
strFile=Replace(strFile,"/ ","\")
If Left(strFile,1)="/" Then
GetPath=MapPath("/") & strFile
Else
GetPath=MapPath(".") & "\" & strFile
End If
End Function
Function GetPath(ByVal strFile)
strFile=Replace(strFile,"/
If Left(strFile,1)="/" Then
GetPath=MapPath("/") & strFile
Else
GetPath=MapPath(".") & "\" & strFile
End If
End Function
ASKER
AlfaNoMore & Ixeus thanks for the suggestions, but neither Server.HTMLEncode nor Server.URLPathEncode work in this case. I am checking for the existance of a file and if the file name gets converted to have percent signs in it then it will not propperly find the file even if it exits.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Points split between me and lxeus?
We don't know what the reasons are for this not working on maytawn's machine, as they never reported the error!
We don't know what the reasons are for this not working on maytawn's machine, as they never reported the error!
Wow, long time ago, I totally forgot about this question lol
Yeah that would be nice, hopefully he gets this mail and does something.
-Ix
Yeah that would be nice, hopefully he gets this mail and does something.
-Ix
Member Name maytawn
Date Account Created 02/25/00
Expert Points 0
Questions Asked 2
Last 10 Grades Given
Question Grading Record 0 Answers Graded / 0 Answers Received
Answers
Questions Answered 0
Last 10 Grades Received
Do you think we'll get the points?
-Ixeus
Date Account Created 02/25/00
Expert Points 0
Questions Asked 2
Last 10 Grades Given
Question Grading Record 0 Answers Graded / 0 Answers Received
Answers
Questions Answered 0
Last 10 Grades Received
Do you think we'll get the points?
-Ixeus
salright, Computer101 will give us the points :-)
That's great :)
Hate it when people do this. They abuse a good system... augh.
Anyway, thanks ahead of time.
Hate it when people do this. They abuse a good system... augh.
Anyway, thanks ahead of time.
ASKER
Please award 50 pts to AlfaNoMore and 50 pts to Ixeus. Neither of their answers actually solved my problem... I had to solve it a different way. But they were helpful so I would like to award the points to them.
Thanks
Thanks
Questions for the 2 experts posted in this topic area.
Thank you
Computer101
Community Support Moderator
Thank you
Computer101
Community Support Moderator
~Ixeus
(think this will work?)