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. General Programming
  3. C#
  4. File transfer

File transfer

Scheduled Pinned Locked Moved C#
sysadmindata-structureshelp
7 Posts 4 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.
  • N Offline
    N Offline
    Niiiissssshhhhhuuuuu
    wrote on last edited by
    #1

    Hello All Gurus, I have one client server application where I am sending files from client to server ,like file upload functionality , File could be any file eg .exe , .jpeg . I am sending data in byte array through network stream /sockets. File is tranfering correctly but when I am trying to open any .pdf or .jpeg file after transfer it is giving me error.cannot open file not in correct format. Only txt file working correctly.. Please advise. Regards :rose:, nishu

    D J P 3 Replies Last reply
    0
    • N Niiiissssshhhhhuuuuu

      Hello All Gurus, I have one client server application where I am sending files from client to server ,like file upload functionality , File could be any file eg .exe , .jpeg . I am sending data in byte array through network stream /sockets. File is tranfering correctly but when I am trying to open any .pdf or .jpeg file after transfer it is giving me error.cannot open file not in correct format. Only txt file working correctly.. Please advise. Regards :rose:, nishu

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      The file your saving on the server is, obviously, being corrupted. Either your client isn't sending the file byte-for-byte, or the server isn't receiving it properly, or it's not writing it byte-for-byte to disk. Without seeing anyn of your client and server code, it's impossible to tell you what's going wrong.

      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      1 Reply Last reply
      0
      • N Niiiissssshhhhhuuuuu

        Hello All Gurus, I have one client server application where I am sending files from client to server ,like file upload functionality , File could be any file eg .exe , .jpeg . I am sending data in byte array through network stream /sockets. File is tranfering correctly but when I am trying to open any .pdf or .jpeg file after transfer it is giving me error.cannot open file not in correct format. Only txt file working correctly.. Please advise. Regards :rose:, nishu

        J Offline
        J Offline
        Judah Gabriel Himango
        wrote on last edited by
        #3

        It probably means the bytes are corrupted -- either you didn't get all the bytes or you didn't get them all in the right order. Do a file compare between original and transferred version to see if they're the same.

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: Virginia Tech Shootings, Guns, and Politics The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        1 Reply Last reply
        0
        • N Niiiissssshhhhhuuuuu

          Hello All Gurus, I have one client server application where I am sending files from client to server ,like file upload functionality , File could be any file eg .exe , .jpeg . I am sending data in byte array through network stream /sockets. File is tranfering correctly but when I am trying to open any .pdf or .jpeg file after transfer it is giving me error.cannot open file not in correct format. Only txt file working correctly.. Please advise. Regards :rose:, nishu

          P Offline
          P Offline
          pbraun
          wrote on last edited by
          #4

          I'm wondering if the server is writing out a text file or a binary file? If the server is writing out a text file, that would explain this behaviour... Phil

          D 1 Reply Last reply
          0
          • P pbraun

            I'm wondering if the server is writing out a text file or a binary file? If the server is writing out a text file, that would explain this behaviour... Phil

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            Yes it would. He's probably using TextReader/Writer, or some other text-only stream, probably even with an Encoding he specified, for reading/writing binary files. That'll corrupt 'em pretty quick.

            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            N 1 Reply Last reply
            0
            • D Dave Kreskowiak

              Yes it would. He's probably using TextReader/Writer, or some other text-only stream, probably even with an Encoding he specified, for reading/writing binary files. That'll corrupt 'em pretty quick.

              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007

              N Offline
              N Offline
              Niiiissssshhhhhuuuuu
              wrote on last edited by
              #6

              Thanks for your reply... I am not using TextReader/Writer ,I am using Filestream to write in the file....my code is as below, stream = client.GetStream(); writer = new System.IO.StreamWriter(stream); freader = new System.IO.FileStream(@"d:\AJAX_process.jpg", System.IO.FileMode.Open); long length = freader.Length; writer.WriteLine(length.ToString()); writer.Flush(); byte[] buffer = new byte[length]; freader.Read(buffer, 0,(Int32)length); freader.Flush(); freader.Close(); //write buffer to network stream// stream.Write(buffer, 0,(Int32)length); stream.Flush(); stream.Close(); writer.Close(); One more question.... Do I need tto sent byte after byte....?? Regards :rose:, nishu

              N 1 Reply Last reply
              0
              • N Niiiissssshhhhhuuuuu

                Thanks for your reply... I am not using TextReader/Writer ,I am using Filestream to write in the file....my code is as below, stream = client.GetStream(); writer = new System.IO.StreamWriter(stream); freader = new System.IO.FileStream(@"d:\AJAX_process.jpg", System.IO.FileMode.Open); long length = freader.Length; writer.WriteLine(length.ToString()); writer.Flush(); byte[] buffer = new byte[length]; freader.Read(buffer, 0,(Int32)length); freader.Flush(); freader.Close(); //write buffer to network stream// stream.Write(buffer, 0,(Int32)length); stream.Flush(); stream.Close(); writer.Close(); One more question.... Do I need tto sent byte after byte....?? Regards :rose:, nishu

                N Offline
                N Offline
                Niiiissssshhhhhuuuuu
                wrote on last edited by
                #7

                sorry I forgot to write but The above is sending data .... stream=client.GetStream(); reader = new System.IO.StreamReader(stream); filename = reader.ReadLine(); length = long.Parse(reader.ReadLine()); byte [] buffer = new byte[length]; stream.Read(buffer, 0,(int) length); fwriter = new System.IO.FileStream(@"d:\new.jpg", System.IO.FileMode.CreateNew); fwriter.Write(buffer, 0,(int) length); MessageBox.Show("write to file done"); Regards :rose:, nishu

                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