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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a link (with spaces) in word 1

Status
Not open for further replies.

jon24422531

Technical User
Jan 27, 2004
295
0
0
GB
Hi

I am trying to create a link that will open in Word, but I am already out of my depth....

I have a table that lists Customer ID's and a path to a word document:
S:\Customer Documents\Customer Information Files\Gosport Loaders [G1] CIF.doc

I then select that using a SQL statement:
Code:
strSQL2 = "select Replace(FileName1, ' ', '%20') from sikbase..KnowledgeBase where custid = '" & CustID & "'"
rsData2.Open strSQL2, MyConn
As you can see, I have tried to allow for the spaces with %20, but in IE it also replaces the % with %2520 !

I then display the result:
Code:
<%if rsData2.eof then%>
<FONT SIZE="+1" COLOR="RED">There is no CIF Link available.</FONT>
<%else%>
<table border='0'>
<%Do While not rsData2.EOF
	Response.Write "<tr>"
	for each fieldItem in rsData2.fields
	Response.Write "<td><a href=" & fieldItem.value & ">Link Here to Word Doc</a></td>"
	next
	Response.Write "</tr>"
	rsData2.MoveNext
Loop%>
</table>
<%end if%>

Despite all that, it will not open the link, where am I going wrong (apart from believing that I can write ASP and HTML code)

Many thanks

Jonathan
 
Code:
Response.Write "<td><a href=""" & fieldItem.value & """>Link Here to Word Doc</a></td>"

or

Code:
Response.Write "<td><a href='" & fieldItem.value & "'>Link Here to Word Doc</a></td>"



TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
server.urlencode(link)

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never in the 'loop' " - DreX 2005
 
vicvirk

Marvellous, it works. Thanks for the quick response.

I have noted that it is OK in IE6 (and IE8 using windows 7 beta) but not in Chrome (nothing happens) or FireFox (Protocol(s) not associated with any program)

Drexor

Not sure what server.urlencode(link) means, how would I use it? Would it overcome the Chrome/FireFox issue although this is an internal web application and IE is the preferred browser.

Jonathan
 
I tried the following in FF and Chrome and it seemed to work fine:

Code:
<%
val = "this is a file.doc"
Response.Write "<td><a href=""" & val & """>Link Here to Word Doc</a></td>"
%>



TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
the urlencode handles the spaces in the linksmaking it address friendly, also considering you're using a web browser, you'd be better off making a virtual path to the housing folder or using a datastream object to parse it out, the issue with using a path forces the file to externally spawn and take considerably more time to load, because of all the current browser security settings etc.

just as a test virtual folder to it and put a virtual link and a direct file link to it and you'll see what i mean regardless of the browser.

and if your DB has all the files physically pathed, you can use translations via replacements such as :

pPath = DB record (physical)
vPath = Server.MapPath("/documents/folder")(virtal folder)

newvPath = Replace(Replace(pPath,vpath,"/documents/folder"), "\", "/")

the slashes replace at the end is to change all the physical slashes to web slashes, the /documents/folder is whatever the root virtual path is to the document folder.

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never in the 'loop' " - DreX 2005
 
Drex,

I did try your method, but in this case where a word file is being linked, it doesn't quite work...

If my word file was called:

"customer profiles.doc"

The urlEncode method would translate that to

"cutomer+profiles.doc"

Since the plus sign is allowed in file names, the server would look for a file named exactlty that: "customer+profiles.doc" which it would not find.

Wrapping the attribute in quotes resolves the issue and the server would look for a file named exactly "cutomer profiles.doc".





TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
urlencode should make the spaces into %20 which the browser should auto interpret
but the urlencoding should only be used in <a href="urlencoded stuff">

and use of the urlencode might be overkill at this point for you too, vs just slapping the virtual path data in a link.

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never in the 'loop' " - DreX 2005
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top