Results 1 to 3 of 3

Thread: Asp.net code for download file

  1. #1
    AllenBrown is offline Senior Member
    Join Date
    Dec 2009
    Posts
    240
    Rep Power
    3

    Default Asp.net code for download file

    Hi. I am working on live project where I use asp.net as front end and SQL as backend. I want one code for my application where user can download file from my website. I tried different code but none of them worked out for me. If you have any code the let me know that is highly appreciated.

  2. #2
    ScottWright is offline Senior Member
    Join Date
    Dec 2009
    Posts
    243
    Rep Power
    3

    Default

    The script that I have mentioned below will definitely help you.

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

  3. #3
    BakerJones is offline Senior Member
    Join Date
    Dec 2009
    Posts
    244
    Rep Power
    3

    Default

    Have you tried below code for download file? If not then try this code:

    Code:
    <%
    try
    {
       System.String filename = "myFile.txt";
    
       // set the http content type to "APPLICATION/OCTET-STREAM
       Response.ContentType = "APPLICATION/OCTET-STREAM";
       
       // initialize the http content-disposition header to
       // indicate a file attachment with the default filename
       // "myFile.txt"
       System.String disHeader = "Attachment; Filename="" + filename +
          """;
       Response.AppendHeader("Content-Disposition", disHeader);
    
       // transfer the file byte-by-byte to the response object
       System.IO.FileInfo fileToDownload = new
          System.IO.FileInfo("C:\downloadJSP\DownloadConv\myFile.txt");
       Response.Flush();
       Response.WriteFile(fileToDownload.FullName);}
    catch (System.Exception e)
    // file IO errors
    {
       SupportClass.WriteStackTrace(e, Console.Error);
    }
    %>

Similar Threads

  1. Code for file upload in VB.net
    By BakerJones in forum Programming
    Replies: 2
    Last Post: 06-17-2010, 01:53 PM
  2. File Download code in asp.net.
    By HowardAdams in forum Programming
    Replies: 4
    Last Post: 04-03-2010, 12:15 PM
  3. File Download code in asp.net.
    By HowardAdams in forum General Internet Terms
    Replies: 4
    Last Post: 04-03-2010, 12:15 PM
  4. Java code to run batch file
    By RodríguezBrown in forum Programming
    Replies: 3
    Last Post: 03-31-2010, 03:53 PM
  5. Can't Download file or videos
    By joshin in forum General Internet Terms
    Replies: 1
    Last Post: 01-10-2009, 07:50 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48