Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys

I have a big problem. I have a class that each time it receives buffer and it should append to a bigger byte array but it do the block copy only the first time, and then it does not copy anything

This is my code:

C#
public Boolean WriteBlobsToDB(byte[] buffer, int offset, int fileSize, string fileName, string fileType, string user, int count, int NChunks, string md5Src,int id)
{
    bool ret = false;
    int l = buffer.Length; // The buffer length is almost 2 MB
    var allData = new byte[fileSize];
    int offst = count * offset; // count is 0 the first timethen each time a new buffer comes, the value of count in count++

    Buffer.BlockCopy(buffer, 0, allData, offst, fileSize);
    if (count == NChunks-1 ) // NChunks is the number of how many time the buffer would be passed here
    {               // the meaning of this if is that, when all the buffer of a file is passed then move to the database and upload the table
        File_List wfl = new File_List();
        fl.FileName = fileName;
        fl.Id = id;
        fl.FileType = fileType;
        fl.MD5 = md5Src;
        fl.Data = new Binary(allData);
        try
        {
            dc.SubmitChanges();
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }

    }

    return ret;
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900