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. Downloading a cab file without any chenge in content or size..

Downloading a cab file without any chenge in content or size..

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelptutorialquestion
3 Posts 2 Posters 10 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.
  • N Offline
    N Offline
    Nicejith
    wrote on last edited by
    #1

    Hi, I have a web application(ASP.net, C#) in which the user is be able to download a .cab file to the PC by clicking on a button after making a file selection. I tried many methods for accomplishing the download task. The code i tried is given below. Response.ContentType = "APPLICATION/OCTET-STREAM"; System.String disHeader = "Download; Filename=\"" + myfilename+ "\""; Response.AppendHeader("Content-Disposition", disHeader); System.IO.FileInfo fileToDownload = new System.IO.FileInfo(myfilepath); Response.Flush(); Response.WriteFile(fileToDownload.FullName); or FileStream MyFileStream = new FileStream(myfilepath, FileMode.Open); long FileSize; FileSize = MyFileStream.Length; byte[] Buffer = new byte[(int)FileSize]; MyFileStream.Read(Buffer, 0, (int)MyFileStream.Length); MyFileStream.Close(); Response.ContentType = "application/octet-stream"; Response.AddHeader("content-disposition", "attachment; filename=" + myfilename); Response.BinaryWrite(Buffer); When i tried these two methods, i could download the files to the PC. The user has to copy the cab file to the Pocket PC device for installing it. The file downloaded through the web application may have some problem so that it cannot be installed on the Pocket PC. When i tried to install the original file from the repository, it worked fine. It means that there occurs some problem with the cab file while it is being downloaded. The original file is having the size 420 KB. But the file downloaded is having size 432 KB. Could anybody guide me to solve the problem? Thanks in advance. Nicejith

    L 1 Reply Last reply
    0
    • N Nicejith

      Hi, I have a web application(ASP.net, C#) in which the user is be able to download a .cab file to the PC by clicking on a button after making a file selection. I tried many methods for accomplishing the download task. The code i tried is given below. Response.ContentType = "APPLICATION/OCTET-STREAM"; System.String disHeader = "Download; Filename=\"" + myfilename+ "\""; Response.AppendHeader("Content-Disposition", disHeader); System.IO.FileInfo fileToDownload = new System.IO.FileInfo(myfilepath); Response.Flush(); Response.WriteFile(fileToDownload.FullName); or FileStream MyFileStream = new FileStream(myfilepath, FileMode.Open); long FileSize; FileSize = MyFileStream.Length; byte[] Buffer = new byte[(int)FileSize]; MyFileStream.Read(Buffer, 0, (int)MyFileStream.Length); MyFileStream.Close(); Response.ContentType = "application/octet-stream"; Response.AddHeader("content-disposition", "attachment; filename=" + myfilename); Response.BinaryWrite(Buffer); When i tried these two methods, i could download the files to the PC. The user has to copy the cab file to the Pocket PC device for installing it. The file downloaded through the web application may have some problem so that it cannot be installed on the Pocket PC. When i tried to install the original file from the repository, it worked fine. It means that there occurs some problem with the cab file while it is being downloaded. The original file is having the size 420 KB. But the file downloaded is having size 432 KB. Could anybody guide me to solve the problem? Thanks in advance. Nicejith

      L Offline
      L Offline
      lucjon
      wrote on last edited by
      #2

      Hi, I don't know if you've tried this, but you could try:

      public void SendFile(String myFilePath) {
      Response.TransmitFile(myFilePath)
      }

      For more information on Response.TransmitFile then go to: http://msdn.microsoft.com/msdnmag/issues/06/09/webdownloads/default.aspx

      N 1 Reply Last reply
      0
      • L lucjon

        Hi, I don't know if you've tried this, but you could try:

        public void SendFile(String myFilePath) {
        Response.TransmitFile(myFilePath)
        }

        For more information on Response.TransmitFile then go to: http://msdn.microsoft.com/msdnmag/issues/06/09/webdownloads/default.aspx

        N Offline
        N Offline
        Nicejith
        wrote on last edited by
        #3

        hi lucjon, i tried that code. still i'm getting the same problem.. there occurs some size variation when i'm trying to download file using all these methods..

        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