Using Server.Urlencode

J

JP SIngh

Hi All

I have users who upload files using my application using ASPUPLOAD
component.

My code uploads the file to a network location and once the upload is finish
I display the hyperlink using the following code

<a href=\myserver\attachments\<%=server.urlencode(rs("FileName"))%>
target="_blank" ><%=rs("Filename")%>

Sometimes the hyperlinks works but sometimes it doesn't.

Should I be using server.urlencode or not.

The problem is my users upload files with all sorts of filename slike
088-888 24(05)-774448.doc which includes spaces, special characters etc.

Can someone offer any help?

Regards
 
P

Phill. W

JP SIngh said:
I display the hyperlink using the following code

<a href=\myserver\attachments\<%=server.urlencode(rs("FileName"))%>
target="_blank" ><%=rs("Filename")%>

Sometimes the hyperlinks works but sometimes it doesn't.

You need quotes around attribute values that mightcontain spaces,
as in

<a href="\myserver\attachments\<%=Server.URLEncode(rs("FileName"))%>"
target="_blank" > said:
Should I be using server.urlencode or not.

Probably and, if only for clarity, I'd prefer to see

<a href="<%= Server.URLEncode( "/myserver/attachments/" & rs("FileName") )
%>" target="_blank" >
<%= Server.HTMLEncode( rs("Filename") ) %>
</a>

HTH,
Phill W.
 
B

Bob Barrows [MVP]

JP said:
Hi All

I have users who upload files using my application using ASPUPLOAD
component.

My code uploads the file to a network location and once the upload is
finish I display the hyperlink using the following code

<a href=\myserver\attachments\<%=server.urlencode(rs("FileName"))%>

Why are you using backslashes in your href ? And why aren't you delimiting
the href value?
target="_blank" ><%=rs("Filename")%>

Sometimes the hyperlinks works but sometimes it doesn't.

Please try to describe your symptoms without using the words "doesn't work".
Should I be using server.urlencode or not.

The problem is my users upload files with all sorts of filename slike
088-888 24(05)-774448.doc which includes spaces, special characters
etc.
So show us what the link looks like when you View Source in the browser.

When I try your example like this:
<a href=images/<%=server.urlencode("088-888 24(05)-774448.doc")%>
target="_blank" ><%="088-888 24(05)-774448.doc"%>


I get source that looks like this:
<a href=images/088%2D888+24%2805%29%2D774448%2Edoc
target="_blank" >088-888 24(05)-774448.doc

which yields this url:
http://webdev/test/images/088-888+24(05)-774448.doc

This link will produce a Page Not Found. If I change the href to
<a href="images/<%="088-888 24(05)-774448.doc"%>"
target="_blank" ><%="088-888 24(05)-774448.doc"%>

I get a link that does open my test document.

So the quick answer is:
use the correct slashes in the url
don't use urlencode
delimit the href value

Now, if the link includes a querystring, the answer will change. The
querystring portion of the url will probably need to be urlencoded. Just the
part after the question mark.

Bob Barrows
 
J

Joe Iano

Hi All

I have users who upload files using my application using ASPUPLOAD
component.

My code uploads the file to a network location and once the upload is finish
I display the hyperlink using the following code

<a href=\myserver\attachments\<%=server.urlencode(rs("FileName"))%>
target="_blank" ><%=rs("Filename")%>

Sometimes the hyperlinks works but sometimes it doesn't.

Should I be using server.urlencode or not.

The problem is my users upload files with all sorts of filename slike
088-888 24(05)-774448.doc which includes spaces, special characters etc.

Can someone offer any help?

Regards
=======================
We re-write file names before saving them, replacing any problematic
characters with underscores.
 

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

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,270
Latest member
TopCryptoTwitterChannels_

Latest Threads

Top