Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. file download problem

file download problem

Scheduled Pinned Locked Moved ASP.NET
helpsysadminquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rajkumar 3
    wrote on last edited by
    #1

    hi, i am using following code to download file from application its working fine in local system but when i configure in server a file is opening with sourse of aspx page can any one help me ? string FilePath = Globals.ApplicationVRoot + "/Downloads/DemoUser.CSV"; string FileName = "DemoUser.CSV"; HttpResponse response = HttpContext.Current.Response; response.ContentType = "application/octet-stream"; response.AddHeader("Content-Disposition", "attachment; filename=" + FileName); response.WriteFile(FilePath.ToString()); response.End();

    A 1 Reply Last reply
    0
    • R rajkumar 3

      hi, i am using following code to download file from application its working fine in local system but when i configure in server a file is opening with sourse of aspx page can any one help me ? string FilePath = Globals.ApplicationVRoot + "/Downloads/DemoUser.CSV"; string FileName = "DemoUser.CSV"; HttpResponse response = HttpContext.Current.Response; response.ContentType = "application/octet-stream"; response.AddHeader("Content-Disposition", "attachment; filename=" + FileName); response.WriteFile(FilePath.ToString()); response.End();

      A Offline
      A Offline
      adatapost
      wrote on last edited by
      #2

      You should write following code: string FilePath = Globals.ApplicationVRoot + "/Downloads/DemoUser.CSV"; byte []b=System.IO.File.ReadAllBytes(FilePath); string FileName = "DemoUser.CSV"; HttpResponse response = HttpContext.Current.Response; response.ClearHeaders(); response.ClearContent(); response.ContentType = "application/octet-stream"; response.AddHeader("Content-Length",b.Length.ToString()); response.AddHeader("Content-Disposition", "attachment; filename=" + FileName); response.BinaryWrite(b); response.Flush(); response.End();

      A DATAPOST COMPUTER CENTRE (K.V Prajapati)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups