Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET WCF service
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
(unknown member)

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



Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 28 Jun 2012
Copyright © CodeProject, 1999-2014
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