Results 1 to 3 of 3

Thread: download text file to client using ASP.NET

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Location
    USA
    Posts
    74

    Thumbs down download text file to client using ASP.NET

    Hi All,

    I am trying to download a text file around 2KB from the server onto the client using ASP.NET

    The downloaded file is incomplete 500bytes only

    The code is as below:

    Response.ContentType = "text/plain"; // Set the file content type to text
    Response.Clear();
    Response.Buffer = true;
    Response.Charset = ""; // Remove the charset from the Content-Type header.
    this.EnableViewState = false; //Turn off the view state.

    Response.AppendHeader( "Content-Disposition","attachment; filename=FileName.txt" );
    Response.AppendHeader( "Content-Length", strFileName.Length.ToString() );
    Response.WriteFile( "Filename.txt" ); // Write the contents of file to client
    Response.Flush();
    Response.End()

    Can anyone tell me what is going wrong.

    Any help is appreciated.
    Thanks
    Manju

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    The Content-Length you are determining by the length of 'strFileName'.
    That doesn't seem correct.
    VB Code:
    1. Response.AppendHeader( "Content-Length", strFileName.Length.ToString() );

    Also be aware, that the OS may appropriate 2-4kb even for a text file that only has 1 byte of data... you can duplicate and confirm this by opening NotePad, and typing 1 character, save and close. Then right-click the file, choose properties...

    You will see the OS has alloted it 2 or 4kb, depending on your OS settings.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Location
    USA
    Posts
    74
    hi nemaroller

    Thanks, I was overlooking the point u mentioned.
    Last edited by manju; Aug 30th, 2004 at 08:27 AM.
    Thanks
    Manju

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width