Problem in downloading file

Last post 12-05-2007 10:07 AM by dineshspillai. 5 replies.

Sort Posts:

  • Problem in downloading file

    12-05-2007, 7:18 AM
    • Loading...
    • dineshspillai
    • Joined on 12-05-2007, 6:53 AM
    • Hyderabad, India
    • Posts 22

    Hi

    I am working on ASP.NET 2.0, trying to download an excel file from the web server.This code is written in a pop up window. I got the code snippet for downloading  from the following link :http://www.xefteri.com/articles/show.cfm?id=8   . Its given below also:

    Dim filePath As String = "\Bin\DownloadBOQ\sampleFile.xls"

    Dim path As String = Server.MapPath("..\..\" + filePath)

    Dim file As FileInfo = New FileInfo(path)

    If file.Exists Then

    Response.Clear()

    Response.AddHeader("Content-Disposition", "attachment; filename=" & "sampleFile.xls")

    Response.AddHeader("Content-Length", file.Length.ToString())

    Response.ContentType = "application/octet-stream"

    Response.WriteFile(file.FullName)

    Response.End() '******************** EXCEPTION"********************************

    End If

    I am having two issues::

    1. The file is not getting downloadeD. the pop up window hangs

    2. An exception occures whlile executing the 'Response.End() ' line . The exception is "System.Threading.ThreadAbortException"

    Please Help me to rectify these two issues.

     

     

    Thanks,

    Dinesh

    Dont forget to click “Mark as Answer” on the post that helped you.
    This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
  • Re: Problem in downloading file

    12-05-2007, 9:16 AM
    • Loading...
    • Deepesh
    • Joined on 07-21-2006, 7:31 AM
    • Posts 111

    Hello,

    Please see the following thread

    http://forums.asp.net/t/1185698.aspx

    and see the code which I have posted there. May this help you.

    Thanks,

    Deepesh Verma

     

    Dont forget to click “Mark as Answer” on the post that helped you.
    This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
  • Re: Problem in downloading file

    12-05-2007, 9:48 AM
    • Loading...
    • dineshspillai
    • Joined on 12-05-2007, 6:53 AM
    • Hyderabad, India
    • Posts 22

    Hi Deepesh,

     

    I tried with your suggestion also. But the exception is still coming.. Is it because of any HTML or page level settings? 

     

    Thanks for your reply

    Dinesh

    Dont forget to click “Mark as Answer” on the post that helped you.
    This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
  • Re: Problem in downloading file

    12-05-2007, 10:00 AM
    Answer
    • Loading...
    • Haissam
    • Joined on 10-05-2006, 6:25 AM
    • Beirut - Lebanon
    • Posts 4,419

    Using Response.End() will make this exception, replace it by the below code

    HttpContext.Current.ApplicationInstance.CompleteRequest()

    As for downloading check below link

     http://dotnetslackers.com/community/blogs/haissam/archive/2007/04/03/Downloading-Files-C_2300_.aspx

    HC

    Haissam Abdul Malak
    MCAD.NET
    | Blog |
  • Re: Problem in downloading file

    12-05-2007, 10:01 AM
    Answer
    • Loading...
    • dineshspillai
    • Joined on 12-05-2007, 6:53 AM
    • Hyderabad, India
    • Posts 22

    Hi

     I have resolved the issue. It looks like a known issue to microsoft : http://support.microsoft.com/kb/312629/

    what they have suggested is use HttpContext.Current.ApplicationInstance.CompleteRequest()  method  instead of Response.End().

    My code is working now.

     

    Thanks

    Dinesh

    Dont forget to click “Mark as Answer” on the post that helped you.
    This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
  • Re: Problem in downloading file

    12-05-2007, 10:07 AM
    • Loading...
    • dineshspillai
    • Joined on 12-05-2007, 6:53 AM
    • Hyderabad, India
    • Posts 22

    Thanks Haissam,

     

    I also found a URL on this . Your solution is perfect.

     

    Thanks,

    Dinesh

    Dont forget to click “Mark as Answer” on the post that helped you.
    This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
Page 1 of 1 (6 items)