Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > view a file in ASP.NET

Reply
Thread Tools

view a file in ASP.NET

 
 
Thelak
Guest
Posts: n/a
 
      08-28-2003
How do I view a text file after I created the file in
ASP.NET?
 
Reply With Quote
 
 
 
 
Jenny K
Guest
Posts: n/a
 
      08-28-2003
"Thelak" <(E-Mail Removed)> wrote in message
news:0cdc01c36db1$6d218c60$(E-Mail Removed)...
> 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();
}



 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      08-29-2003
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" <(E-Mail Removed)> wrote in message
news:0cdc01c36db1$6d218c60$(E-Mail Removed)...
> How do I view a text file after I created the file in
> ASP.NET?



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Edit Mode of Grid View and Detail View Control ? Luqman ASP .Net 2 02-01-2006 08:14 AM
Google's: How to change from Summary view to Title view? lbbss Computer Support 6 09-29-2005 06:42 PM
Icon View and list View in ASP.NET =?Utf-8?B?UmFlZCBTYXdhbGhh?= ASP .Net 0 03-07-2005 06:53 PM
How to make a week view and day view calendar just like month view calendar in .NET ? Parthiv Joshi ASP .Net Web Controls 1 07-06-2004 03:15 PM
Wierd error when going to Design View from HTML view VB Programmer ASP .Net 1 07-10-2003 03:20 PM



Advertisments