view a file in ASP.NET

Discussion in 'ASP .Net' started by Thelak, Aug 28, 2003.

  1. Thelak

    Thelak Guest

    How do I view a text file after I created the file in
    ASP.NET?
    Thelak, Aug 28, 2003
    #1
    1. Advertising

  2. Thelak

    Jenny K Guest

    "Thelak" <> wrote in message
    news:0cdc01c36db1$6d218c60$...
    > 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)).Decrypting(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();
    }
    Jenny K, Aug 28, 2003
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:0cdc01c36db1$6d218c60$...
    > How do I view a text file after I created the file in
    > ASP.NET?
    Kevin Spencer, Aug 29, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VB Programmer
    Replies:
    1
    Views:
    583
    VB Programmer
    Jul 10, 2003
  2. =?Utf-8?B?UmFlZCBTYXdhbGhh?=

    Icon View and list View in ASP.NET

    =?Utf-8?B?UmFlZCBTYXdhbGhh?=, Mar 7, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    483
    =?Utf-8?B?UmFlZCBTYXdhbGhh?=
    Mar 7, 2005
  3. Luqman
    Replies:
    2
    Views:
    3,794
    Luqman
    Feb 1, 2006
  4. RichB
    Replies:
    7
    Views:
    5,677
    dkmorris1999
    Sep 21, 2009
  5. Parthiv Joshi
    Replies:
    1
    Views:
    646
    Samuel L Matzen
    Jul 6, 2004
Loading...

Share This Page