File transfer
-
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
-
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
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 -
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
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
-
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
-
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
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 -
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, 2007Thanks 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
-
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
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