<txt src= ...> equivalent of <img src= ...>

S

Steve Richter

Is there a way to pull text from a url into a web page? Similar to how
the <img> element uses a URL to access the image to display.
<txt src="http:\\www....." >

thanks,

-Steve
 
K

Ken Cox - Microsoft MVP

Hi Steve,

This feels like a hack but it does accomplish what you want.

It uses WebClient to fetch the file as a string. (This is ASP.NET 2.0 code)

Perhaps this will spark someone to come up with a more elegant solution?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
Dim wc As New System.Net.WebClient
Dim sb As New StringBuilder
sb.Append(wc.DownloadString("http://www.kencox.ca/textfile.txt"))
Literal1.Text = sb.ToString
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Webclient Text</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:literal id="Literal1" text="" runat="server"></asp:literal>
</div>
</form>
</body>
</html>
 
K

Kevin Spencer

IFrame.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
We got a sick zebra a hat,
you ultimate tuna.
 
L

Laurent Bugnion

Hi,

Steve said:
Is there a way to pull text from a url into a web page? Similar to how
the <img> element uses a URL to access the image to display.
<txt src="http:\\www....." >

thanks,

-Steve

The best (IMHO) and cleanest way is to use a XmlHttp object to send a
GET request for the text file, and then use the callback mechanism to
include it in your HTML document using DOM.

For more info, check XmlHttp on Google, and remember that you can also
use this object client-side with JavaScript (this is what is used to
make WebServices work)

HTH,
Laurent
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top