SPWeb.GetFileAsString(URL) causing the problem, and throws COMException, if an XML file size is more than 10 MB

PROBLEM : SPWeb.GetFileAsString(URL) method throws COMException, if we pass XML file and its size is more than 10 MB


Instead of using SPWeb.GetFileAsString(URL), use SPFile.OpenBinary() method.

try {
string str = Url.Text;
using (SPSite portalSite = new SPSite(str)){
SPWeb web = portalSite.OpenWeb();
SPFile file = web.GetFile(str);
byte[] content = file.OpenBinary();
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string str1 = enc.GetString(content);
//string str1 = web.GetFileAsString(str);
MessageBox.Show("File fetched successfully");
catch(Exception ex){