Click here to Skip to main content
12,953,541 members (52,462 online)
Rate this:
 
Please Sign up or sign in to 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.

 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 4-Jun-12 22:19pm
cpquest1.8K

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
ppolymorphe 2,020
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 28 Jun 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100