locked
download a file from sever to client RRS feed

  • Question

  • User669459161 posted

    Hi all,

                   please provide code for following "download a file from sever to client"

    Regards

    VeerendraNadh

     

    Sunday, January 29, 2012 12:23 AM

Answers

  • User896700311 posted

    Hi,

    try this sample:

              Response.ContentType="application/txt";
              Response.AddHeader( "content-disposition","attachment; filename=file1.txt");
                    
              FileStream sourceFile = new FileStream(@"C:\inetpub\wwwroot\folder1\folder2\hearing.txt", FileMode.Open);
              long FileSize;
              FileSize = sourceFile.Length;
              byte[] getContent = new byte[(int)FileSize];
              sourceFile.Read(getContent, 0, (int)sourceFile.Length);
              sourceFile.Close();
    
              Response.BinaryWrite(getContent);
    Any doubt, post your comment.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 29, 2012 1:00 AM

All replies

  • User896700311 posted

    Hi,

    try this sample:

              Response.ContentType="application/txt";
              Response.AddHeader( "content-disposition","attachment; filename=file1.txt");
                    
              FileStream sourceFile = new FileStream(@"C:\inetpub\wwwroot\folder1\folder2\hearing.txt", FileMode.Open);
              long FileSize;
              FileSize = sourceFile.Length;
              byte[] getContent = new byte[(int)FileSize];
              sourceFile.Read(getContent, 0, (int)sourceFile.Length);
              sourceFile.Close();
    
              Response.BinaryWrite(getContent);
    Any doubt, post your comment.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 29, 2012 1:00 AM
  • User-1956819616 posted
    Response.ContentType = "image/jpeg"
    Response.AppendHeader("Content-Disposition","attachment; filename=SailBig.jpg")
    Response.TransmitFile( Server.MapPath("~/images/sailbig.jpg") )
    Response.End()
    Sunday, January 29, 2012 4:22 PM
  • User-606151534 posted

    hi

    Response.ContentType = "Love/jpeg"
    Response.AppendHeader("Content-Disposition","attachment; filename=SailBig.jpg")
    Response.TransmitFile( Server.MapPath("~/images/Love.jpg") )
    Response.End()

    or

    see this url

    http://msdn.microsoft.com/en-us/library/aa478985.aspx

    thank u

    Saturday, February 4, 2012 9:53 AM