Generate URL link for name with space between characters

U

uandme72

I want to generate url link with <a> </a> tags such that the href="abc def
ghi" has space characters present in the link.

However, I get only the first part of the file name as the link (abc from
the above example) instead of the full
name (abc def ghi).
I tried server.htmlencode and server.urlencode but the link is not
getting generated as expected.

Kindly advise on how to get the url link of the full file name which has
space in the name.

uandme72
 
D

Daniel Crichton

uandme72 wrote on Thu, 26 Mar 2009 21:16:39 +0530:
I want to generate url link with <a> </a> tags such that the href="abc
def ghi" has space characters present in the link.
However, I get only the first part of the file name as the link (abc
from the above example) instead of the full name (abc def ghi).
I tried server.htmlencode and server.urlencode but the link is not
getting generated as expected.
Kindly advise on how to get the url link of the full file name which
has space in the name.


Filenames with spaces need to be passed in URLs with %20 replacing the
spaces. Neither Server.HTMLEncode nor Server.URLEncode will do this -
HTMLEncode is used for encoding text to be used in HTML (and space are valid
HTML characters), and URLEncode is for encoding querystring/post field name
and values.

eg.

<%
the_link_filename = "my file.htm"
%>

<a href="<%=Replace(the_link_filename," ","%20")%>">text</a>
 
U

uandme72

Daniel Crichton said:
uandme72 wrote on Thu, 26 Mar 2009 21:16:39 +0530:






Filenames with spaces need to be passed in URLs with %20 replacing the
spaces. Neither Server.HTMLEncode nor Server.URLEncode will do this -
HTMLEncode is used for encoding text to be used in HTML (and space are
valid HTML characters), and URLEncode is for encoding querystring/post
field name and values.

Apart from space characters, are there any other special characters for
which we need to plan beforehand and insert code for replacing them as
indicated for the space characters above.
 
A

Adrienne Boswell

Apart from space characters, are there any other special characters for
which we need to plan beforehand and insert code for replacing them as
indicated for the space characters above.

I try to stay away from anything that is not a alphabetic character or a
number, with the exception of underline
 
D

Daniel Crichton

uandme72 wrote on Fri, 27 Mar 2009 00:06:41 +0530:

Apart from space characters, are there any other special characters for
which we need to plan beforehand and insert code for replacing them as
indicated for the space characters above.


Yes. Anything in a filename which is part of the URL specification, eg. & ?
# ; / and likely a few more besides. Personally I never use anything other
than letters, numbers, hyphens, and underscores in filenames due to the
problems anything else can cause.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top