View Feed
group-icon
Coffee Room
Discuss anything here - everything that you wish to discuss with fellow engineers.
12773 Members
Join this group to post and comment.
subashree
subashree • Jan 31, 2012

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;
}
}
Is the first image a full one? I don't think so... If that shouldn't be a full one, then the rest are missing their headers. So, just prepend the headers to the rest of the files and check it out... 😀
subashree
subashree • Feb 5, 2012
Praveen-Kumar
Is the first image a full one? I don't think so... If that shouldn't be a full one, then the rest are missing their headers. So, just prepend the headers to the rest of the files and check it out... 😀
no...i dont get wat u r trying to say...wen i run this code the input image file s supposed to b stripped...wen i give the number of splits as 3(say) then the first splitted image has the stripped image(1/3rd of the image..remaining ll be blank) but the other files should hav the remaining part of the image..but it s an invalid...my doubt is if the snippet works for first iteration it should do for the rest too...

and wad did u mean by sayib add headers
[​IMG]
This was the frames I was talking about... Did you miss the PNG Signature in the rest of the frames???

Share this content on your social channels -