By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,930 Members | 1,465 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,930 IT Pros & Developers. It's quick & easy.

Using Server.Urlencode

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"JP SIngh" <no**@none.com> wrote in message
news:ug**************@TK2MSFTNGP09.phx.gbl...
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" ><%=rs("Filename")%></a>
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.
Jul 22 '05 #2

P: n/a
JP SIngh wrote:
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%2D888+...2D774448%2Edoc

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

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #3

P: n/a

"JP SIngh" <no**@none.com> wrote in message
news:ug**************@TK2MSFTNGP09.phx.gbl...
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.
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.