471,073 Members | 1,166 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

Creating a dynamic file link

BD
This is probably fairly simple but I've looked at so much code an the last
few days that my brain is fried.
In the past I had an HTML page that contained a lot of code items and each
item was contained in it's own hidden <div>. The div was displayed by
extracting the bookmark, for example mypage.htm#sec2 would display the div
with the id of sec2. It worked but as you can imagine it was rather clumsy
as the number of items increased. At the bottom of each div were some text
links. One pointed to a VBScript function that copied the inner text of the
div to the clipboard the other pointed to a zip file that was downloaded. I
have now re-written it as an aspx page that uses a query string to load the
contents of a text file into a div. It's called using mypage.aspx?udf=test.
Here is the the top portion of the page.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ Page Language="VB" Debug="true" runat="server"%>
<%@ Import Namespace="System.IO" %>
<%
Dim fn As String = Request.QueryString("udf")
Dim udf = fn & ".txt"
Dim dFile = fn & ".zip"
Dim fp As StreamReader
Dim dFldr As String = Server.MapPath("Files\")
Dim uTxt As String
Dim fDate = File.GetLastWriteTime(Server.MapPath("Code\") &
udf).ToString("D")
fp = File.OpenText(Server.MapPath("Code\") & udf)
uTxt = fp.ReadToEnd()
fp.Close()
%>
<html>
Using the example above, the variable udf causes the test.txt file to be
loaded in the "data" div.
The copy to clipboard function is just fine. It's called using
<a href="javascript:CpyCode()">Copy to clipboard</a>
The CpyCode function has the div with the id="data" hard coded, since now
there is only the one.

Now the problem comes with this old line
<a href="files/test.zip">Download File</a>
How would I write a function that would create a link from the variable
dFile?

TIA
Jun 27 '08 #1
1 1279
BD
Got it! Thanks anyway. It was as simple as replacing the old <a
href="files/test.zip">Download File</a></pline with the following
<%response.write("<a href=""files/" & dFile & """>Download File</a></p>")%>

"BD" <Ju****@nothome.netwrote in message
news:ek**************@TK2MSFTNGP03.phx.gbl...
This is probably fairly simple but I've looked at so much code an the last
few days that my brain is fried.
In the past I had an HTML page that contained a lot of code items and each
item was contained in it's own hidden <div>. The div was displayed by
extracting the bookmark, for example mypage.htm#sec2 would display the div
with the id of sec2. It worked but as you can imagine it was rather
clumsy as the number of items increased. At the bottom of each div were
some text links. One pointed to a VBScript function that copied the inner
text of the div to the clipboard the other pointed to a zip file that was
downloaded. I have now re-written it as an aspx page that uses a query
string to load the contents of a text file into a div. It's called using
mypage.aspx?udf=test. Here is the the top portion of the page.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ Page Language="VB" Debug="true" runat="server"%>
<%@ Import Namespace="System.IO" %>
<%
Dim fn As String = Request.QueryString("udf")
Dim udf = fn & ".txt"
Dim dFile = fn & ".zip"
Dim fp As StreamReader
Dim dFldr As String = Server.MapPath("Files\")
Dim uTxt As String
Dim fDate = File.GetLastWriteTime(Server.MapPath("Code\") &
udf).ToString("D")
fp = File.OpenText(Server.MapPath("Code\") & udf)
uTxt = fp.ReadToEnd()
fp.Close()
%>
<html>
Using the example above, the variable udf causes the test.txt file to be
loaded in the "data" div.
The copy to clipboard function is just fine. It's called using
<a href="javascript:CpyCode()">Copy to clipboard</a>
The CpyCode function has the div with the id="data" hard coded, since now
there is only the one.

Now the problem comes with this old line
<a href="files/test.zip">Download File</a>
How would I write a function that would create a link from the variable
dFile?

TIA


Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Daniel Keller | last post: by
5 posts views Thread by Paramesh | last post: by
15 posts views Thread by David Thielen | last post: by
2 posts views Thread by SAL | last post: by
2 posts views Thread by JWL | last post: by
12 posts views Thread by Lazoris | last post: by
13 posts views Thread by jkimbler | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.