Click here to Skip to main content
15,880,972 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Madam/Sir,


I want to know -How to break 300 KB from Html(1MB) using C#.
condition 1. some tags are open but not closed due to completed 300 KB.

How to maintain closing tags and How to open next tags ?
Please suggest me.


FOr eg- I have 1 html file and size is 1 MB.

Then I want to break in 300 kB from html file.

file included tags - p,div,table header(h1 to h6).

Please help me.
Posted
Updated 22-Jan-14 18:54pm
v2
Comments
thatraja 21-Jan-14 7:36am    
What's the purpose?

1 solution

[UPDATED]

try this.

C#
static void FileSplit(string ipath)
{
    // open input file
    using (FileStream fsi = File.OpenRead(ipath))
    {
        bool completed = false; // completed when all parts created
        int i = 0; // part index
        byte[] buff = new byte[1024]; // read/write buffer

        while (!completed)
        {
            // part file path
            string opath = string.Format("{0}_{1}", ipath, i++);
            // processed part size
            int partsize = 0;

            // open part file
            using (FileStream fso = File.Create(opath))
            {
                // requirement for max part size
                while (partsize < 300000)
                {
                    // read from input file
                    int n = fsi.Read(buff, 0, 1024);
                    if (n > 0)
                    {
                        partsize += n;
                        // write to part file
                        fso.Write(buff, 0, n);
                    }
                    completed = (n < 1024 || i > 10);
                    // break loop if completed
                    if (completed)
                        break;
                }
            }
        }
    }
} // end of file split
 
Share this answer
 
v2
Comments
ArunRajendra 21-Jan-14 23:22pm    
This reads 300 bytes and not 300kb.
Vedat Ozan Oner 22-Jan-14 4:52am    
oops, I am correcting it in a minute :)
Vedat Ozan Oner 22-Jan-14 5:40am    
now corrected
Mahendra kumar das 23-Jan-14 6:47am    
code is working fine.
But some problem -- Suppose div is open and 300 KB is completed .div is not closed.
How to closee div or any tag like table, tr,td,p?
How to maintain above tag ?
Please suggest me
Vedat Ozan Oner 23-Jan-14 7:30am    
it is impossible because of the nature of html. at some point, you will have to break a node. for example, you manage to include a tag in a part. but its parent will have to be broken, then. it ends up topmost 'body' at least. you have to break at least one.

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