[color=#ff3333]آپدیت شد
[/color]


سلام
تو این پست میخوام یه پروژه بسیار کاربردی رو براتون بذارم
همونطور که از عنوان این تاپیک معلومه این پروژه File Splitter and joiner هست یعنی فایلها رو به پارت های کوچیک تر تقسیم میکنه و بعد هم میتونه دوباره اونها رو به هم بچسبونه تا فایل اولی ساخته بشه.

برای Split:

private void SplitFile(string FileInputPath, string FolderOutputPath, int OutputFiles)
        {//Project Downloaded From http://SoftAfzar.net
            // Store the file in a byte array
            Byte[] byteSource = System.IO.File.ReadAllBytes(FileInputPath);
            // Get file info
            FileInfo fiSource = new FileInfo(txtSourceFile.Text);
            // Calculate the size of each part
            int partSize = (int)Math.Ceiling((double)(fiSource.Length / OutputFiles));
            // The offset at which to start reading from the source file
            int fileOffset = 0;

            // Stores the name of each file part
            string currPartPath;
            // The file stream that will hold each file part
            FileStream fsPart;
            // Stores the remaining byte length to write to other files
            int sizeRemaining = (int)fiSource.Length;

            // Loop through as many times we need to create the partial files
            for (int i = 0; i < OutputFiles; i++)
            {
                // Store the path of the new part
                currPartPath = FolderOutputPath + "\" + fiSource.Name + "." + String.Format(@"{0:D4}", i) + ".part";
                // A filestream for the path
                if (!File.Exists(currPartPath))
                {
                    fsPart = new FileStream(currPartPath, FileMode.CreateNew);
                    // Calculate the remaining size of the whole file
                    sizeRemaining = (int)fiSource.Length - (i * partSize);
                    // The size of the last part file might differ because a file doesn't always split equally
                    if (sizeRemaining < partSize)
                    {
                        partSize = sizeRemaining;
                    }
                    fsPart.Write(byteSource, fileOffset, partSize);
                    fsPart.Close();
                    fileOffset += partSize;
                }
            }
        }

برای join:

       private void JoinFiles(string FolderInputPath, string FileOutputPath)
        {//Project Downloaded From http://SoftAfzar.net Visit Us :)
            DirectoryInfo diSource = new DirectoryInfo(FolderInputPath);
            FileStream fsSource = new FileStream(FileOutputPath, FileMode.Append);

            foreach (FileInfo fiPart in diSource.GetFiles(@"*.part"))
            {
                Byte[] bytePart = System.IO.File.ReadAllBytes(fiPart.FullName);
                fsSource.Write(bytePart, 0, bytePart.Length);
            }
            fsSource.Close();
        }

مثال نحوه استفاده:

       private void btnJoin_Click(object sender, EventArgs e)
        {
            if (saveOutput.ShowDialog() == DialogResult.OK)
            {
                JoinFiles(txtSourceFolder.Text, saveOutput.FileName);
            }
        }

        private void btnBrowseFile_Click(object sender, EventArgs e)
        {
            if (openSource.ShowDialog() == DialogResult.OK)
            {
                txtSourceFile.Text = openSource.FileName;
            }
        }

        private void btnSplit_Click(object sender, EventArgs e)
        {
            try
            {
                if (saveToFolder.ShowDialog() == DialogResult.OK)
                {
                    SplitFile(txtSourceFile.Text, saveToFolder.SelectedPath, (int)numOutputs.Value);
                    MessageBox.Show("Operation Compeleted", "Done",MessageBoxButtons.OK,MessageBoxIcon.Information);
                }
            }
            catch(Exception err)
            {
                MessageBox.Show(err.Message, "Error");
            }
        }
    }
}