Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VBNET,ASPNET
Expertise: Intermediate
Feb 2, 2002

Sending files to the browser

The ASP.NET Response object has been greatly expanded in its capability to send output to the client browser. For example, the WriteFile method can send the contents of any text, HTML, or XML file to the browser; in classic ASP you have to load the file in memory and then pass its contents to a Write method to reach the same effect. For example, you can use this method to apply a common frame and style, typically a menu bar or footer, to any .txt file:

' Get the name of the requested document (passed on the query string).
Dim path As String = Request.QueryString("doctitle") & ".txt"
' Convert to a physical path.
path = Request.MapPath(path)
If System.IO.File.Exists(path) Then
    ' If the file exists, send it to the browser as HTML.
    Response.Write("<HTML><BODY>")
    Response.Write("<H1>Here's the document you've requested</H1>")
    Response.WriteFile(path)
    Response.Write("</BODY></HTML>")
Else
    ' Else display an error message.
    Response.Write("Sorry, no document with this name.")
End If
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date