Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

Select The File And Split As Chunks:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace FileSplitter
{
public partial class Split : Form
{
public Split()
{
InitializeComponent();
}

private void SplitFile(string FileInputPath, string


FolderOutputPath, int OutputFiles)
{
// 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;
}
}
}

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)


{
if (saveToFolder.ShowDialog() == DialogResult.OK)
{
SplitFile(txtSourceFile.Text, saveToFolder.SelectedPath,
(int)numOutputs.Value);
}
}
private void button1_Click(object sender, EventArgs e)
{
Save s = new Save();
s.Show();

private void Split_Load(object sender, EventArgs e)


{

private void btndownload_Click(object sender, EventArgs e)


{
responsetime rp = new responsetime();
rp.Show();
}
}
}
Screenshot :

Select The File And Split As Chunks:

You might also like