c# -help in finding logical error in file stripping.
the following is a snippet for splitting the file(from parameter FileInputPath) into the number of splits(given as outputfiles) to the specified folder (FolderOUtputPath).
the files are split.(my file s an image here). wen the image s split ..oli the first split has the stripped image...the other files r invalid. pls help me ...
privatevoid SplitFile(string FileInputPath, string FolderOutputPath, intOutputFiles)
{
Byte[] byteSource = System.IO.File.ReadAllBytes(FileInputPath);
FileInfo fiSource = newFileInfo(textBox1.Text);
int partSize = (int)Math.Ceiling((double)(fiSource.Length / OutputFiles));
int fileOffset = 0;
string currPartPath;
FileStream fsPart;
int sizeRemaining = (int)fiSource.Length;
for (inti = 0; i < OutputFiles; i++)
{
currPartPath = FolderOutputPath +
"\\" + String.Format(@"{0: D4}", i) + fiSource.Name;
if (!File
.Exists(currPartPath))
{
fsPart =
newFileStream(currPartPath, FileMode
.CreateNew);
sizeRemaining = (
int
)fiSource.Length - (i * partSize);
if
(sizeRemaining < partSize)
{
partSize = sizeRemaining;
}
fsPart.Write(byteSource, fileOffset, partSize);
fsPart.Close();
fileOffset += partSize;
}
}
the files are split.(my file s an image here). wen the image s split ..oli the first split has the stripped image...the other files r invalid. pls help me ...
privatevoid SplitFile(string FileInputPath, string FolderOutputPath, intOutputFiles)
{
Byte[] byteSource = System.IO.File.ReadAllBytes(FileInputPath);
FileInfo fiSource = newFileInfo(textBox1.Text);
int partSize = (int)Math.Ceiling((double)(fiSource.Length / OutputFiles));
int fileOffset = 0;
string currPartPath;
FileStream fsPart;
int sizeRemaining = (int)fiSource.Length;
for (inti = 0; i < OutputFiles; i++)
{
currPartPath = FolderOutputPath +
"\\" + String.Format(@"{0: D4}", i) + fiSource.Name;
if (!File
.Exists(currPartPath))
{
fsPart =
newFileStream(currPartPath, FileMode
.CreateNew);
sizeRemaining = (
int
)fiSource.Length - (i * partSize);
if
(sizeRemaining < partSize)
{
partSize = sizeRemaining;
}
fsPart.Write(byteSource, fileOffset, partSize);
fsPart.Close();
fileOffset += partSize;
}
}
0