473,383 Members | 1,837 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

view a file in ASP.NET

How do I view a text file after I created the file in
ASP.NET?
Nov 17 '05 #1
2 1959
"Thelak" <th********@hotmail.com> wrote in message
news:0c****************************@phx.gbl...
How do I view a text file after I created the file in
ASP.NET?


You're going to get many different responses to your question.
Why don't you just Response.Redirect the browser to the text file?

Or do you want to get more elaborate and read the file into a buffer and
Response.BinaryWrite() the buffer like this:?
the following is for reading a pdf file on the server.
private void Page_Load(object sender, System.EventArgs e){
if(Request.QueryString["encryptedFilename"]!=null &&
Request.QueryString["encryptedFilename"] != ""){
string fileName = (new
SymmCrypto(SymmCrypto.SymmProvEnum.RC2)).Decryptin g(Request.QueryString["enc
ryptedFilename"],"myEncryptionKey");
System.IO.FileStream stream = System.IO.File.OpenRead(fileName);
byte[] buffer = readFully(stream);
stream.Close();
File.Delete(fileName);
sendToBrowser(buffer);
}
}
private byte[] readFully(System.IO.Stream stream){
byte[] buffer = new byte[32768];
using(MemoryStream ms = new MemoryStream()){
while(true){
int read = stream.Read(buffer,0,buffer.Length);
if(read <= 0){
return ms.ToArray();
}
ms.Write(buffer,0,read);
}
}
}
private void sendToBrowser(byte[] buffer){
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition","inline;filename=dummy.pdf");

Response.BinaryWrite(buffer);
Response.Flush();
Response.Close();
}

Nov 17 '05 #2
Open it in a text editor?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"Thelak" <th********@hotmail.com> wrote in message
news:0c****************************@phx.gbl...
How do I view a text file after I created the file in
ASP.NET?

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Pete Wason | last post by:
Hiall! I have a demo viewer page for javascript stuff that has three buttons "DEMO" "HTML" and "JSCR", and an IFRAME called 'viewer'. Initially, the IFRAME gets loaded with the actual demo...
4
by: Neil | last post by:
I just resolved a strange situation I was having with an ODBC linked SQL 7 view in an Access 2000 MDB file, and I'm trying to get some understanding as to what happened. The linked view was...
18
by: Lorem Ipsum | last post by:
interesting! I just found a page in which Explorer's View Source does nothing! How did they do that?
20
by: Neil | last post by:
I have an Access 2000 MDB file with a SQL 7 back end. I have a main table with 50,000 records; and I have a selections table with 50,000 records for each machine that uses the database (about...
1
by: Jerry Tovar | last post by:
I am using .Net 2003 on a XPPro running IIS. I am unable to view any of my ASPX webforms in a browser unless I modify the .ASPX file and replace Codebehind="employee.aspx.cs" with...
3
by: Guadala Harry | last post by:
Is it possible to view the contents of an external CSS style sheet that is referenced from any web page being viewed in the browser (IE6)? If so how? The css file physically lives on the server,...
0
by: ¿ Mahesh Kumar | last post by:
I have created a XML file as datasource which i 'm binding to a grid view control. During runtime I'm capturing items in XML file and displaying in a GRID VIEW control. but i want to remove or...
1
by: Nogusta123 | last post by:
Hi, I have had a lot of problems getting web pages, master pages and content pages to render in VS2005 design view the same as they would in Internet Explorer. I did a lot of looking on the...
2
by: cckelly | last post by:
Hello, all! I need help. There is a "view" in a SQL Server 7 database that contains all the data I need. I want to create an Excel file (version Excel 2000). I want the file to open the view and...
1
by: Farhaad Faaique | last post by:
Dears, how can i enable a from's design view when it is disabled? (the database doesn't have any passwords to be accessed but it has password for vba codes). thanks in advance, Farhaad
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.