data is not saving properly in memory stream C#
===

I am using HtmlAgilityPack and saving an html document in MemoryStream :

           MemoryStream ms = new MemoryStream();
           HtmlDocument doc = new HtmlDocument();
           doc.load(path);
           . 
           .
           doc.Save(ms);

Now the problem is that sometime the document saved fully and sometimes some contents of the document ( from end ) lost, it did`nt save with the document. Can anybody tell me why this is happening and how can i solve this? 