Click here to Skip to main content
15,886,860 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all,

I was working on a project that need to send and receive files using WCF service.
i have created a chunk. what i need is what i did is correct or wrong.

here is my code.

C#
using (FileStream fStream = File.OpenRead(Isafile.FullName))
                   {
                       totalBytes += (int)fStream.Length;
                       byte[] b = new byte[fStream.Length];
                       fStream.Read(b, 0, (int)fStream.Length);
                       fStream.Flush();
                       int getBytes = 0;
                       // if the file size greater or equal to 64kb
                       if (b.Length >= (1024 * 64))
                       {

                           int num64Bbs = b.Length / (1024 * 64);             // Get number of 64kb in the files(i.e.,using the byte[])
                           int remainingBytes = b.Length % (1024 * 64);       // Get remaining byte
                           for (int j = 0; j < num64Bbs; j++)
                           {
                               try
                               {
                                   byte[] chunk = new byte[(1024 * 64)];      // Create a New byte array to copy
                                   Buffer.BlockCopy(b, getBytes, chunk, 0, (1024 * 64));   //copy 64kb from total byte to new byte.
                                   fileList.Add(new FileList { FileByte = chunk, FileInformation = Isafile, obj = null });      // add the file detail and Chunk in a list
                                   getBytes += (1024 * 64) + 1;        // Increment the offset
                               }
                               catch (Exception) { break; }
                           }
                           if (remainingBytes > 0)     // For remaining Byte it any
                           {
                               byte[] chunk = new byte[remainingBytes];
                               Buffer.BlockCopy(b, b.Length - remainingBytes, chunk, 0, remainingBytes);
                               fileList.Add(new FileList { FileByte = chunk, FileInformation = Isafile, obj = null });
                           }
                       }
                       // Lesser than 64 KB
                       else
                       {
                           fileList.Add(new FileList { FileByte = b, FileInformation = Isafile, obj = null });
                       }

                   }


The above is the code which i use to create a chunk now what i need is i have to know weather the code which i have did is correct. then i need to

know how to send (from on end of Client) and receive (another end of client) the files accross WCF
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900