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;
}
}

Replies

  • PraveenKumar Purushothaman
    PraveenKumar Purushothaman
    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
    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
  • PraveenKumar Purushothaman
    PraveenKumar Purushothaman
    [​IMG]
    This was the frames I was talking about... Did you miss the PNG Signature in the rest of the frames???

You are reading an archived discussion.

Related Posts

Hi, Can someone suggest good reference books for the following subjects (Indian and foreign ones included, if available). I went through a few titles of these books, but they didn't...
title of this blog has astonished me
Hi Everyone, I still have one semester remaining to finish my second year studies. What I’m wondering about is what to do over the summer, the reason I choose to...
hey friends,,,,we are organising a COMEDY CHALLENGE in our college .would u plz suggest me any decent name for d event
Greetings CEians, To all engineers around the area of Malaysia, University Tunku Abdul Rahman (UTAR) from Malaysia is proud to announce that we are hosting the next IEEE STUDENT conference...