Solved

stringbuilder out of memory error

Posted on 2014-07-29
5
82 Views
Last Modified: 2016-06-21
I have some code that gets documents from a sharepoint library via a webservice.
During testing I attempted to get a 220mb document and get this error
An error has occurred: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. at System.Text.StringBuilder.ToString() at System.Xml.XmlTextReaderImpl.ParseText()

Is there anything I can do to get around this?
This is the code I am using.

 public void CopyFile()
        {
            string webUrl = "http://xxx";
            FileCopy.Copy copyService = new FileCopy.Copy();
            copyService.Url = webUrl +"/_vti_bin/copy.asmx";
            NetworkCredential m_credentials = new NetworkCredential("x", "x", "x");
                 copyService.Credentials = m_credentials;

            //Source and Destination Document URLs
             string sourceUrl = "http://x/Documents/1784.pdf";
             string destinationUrl = "C:\\Documents\\1784.pdf";

            //Variables for Reading metadata’s of a document
             FileCopy.FieldInformation fieldInfo = new FileCopy.FieldInformation();
             FileCopy.FieldInformation[] fieldInfoArray = { fieldInfo };
             FileCopy.CopyResult cResult1 = new FileCopy.CopyResult();
             FileCopy.CopyResult cResult2 = new FileCopy.CopyResult();
             FileCopy.CopyResult[] cResultArray = { cResult1, cResult2 };

        

            //Receive a Document Contents  into Byte array (filecontents)
             byte[] fileContent; // no need to initialize the GetItem takes care of that.
             copyService.GetItem(sourceUrl, out fieldInfoArray, out fileContent);

            //Create a new file and write contents to that document
             FileStream fStream = new FileStream(destinationUrl, FileMode.Create, FileAccess.ReadWrite);
            fStream.Write(fileContent, 0, fileContent.Length);
            fStream.Close();
        }
    }

Open in new window

0
Comment
Question by:QPR
  • 2
  • 2
5 Comments
 
LVL 40
ID: 40228342
What line triggers the error.

Since the error happens in a StringBuilder and there is none in your code, it is probably triggered inside of something you are calling.

What are that FileCopy and class that you are using? If this is one of your classes, look in there. If it is something from a third party, get in contact with them.
0
 
LVL 29

Author Comment

by:QPR
ID: 40228350
It is failing on this line
copyService.GetItem(sourceUrl, out fieldInfoArray, out fileContent);

GetItem is a sharepoint webservice.
Your post has led me in the right direction tough.
Seems there is a 50mb limt lthough this can be configured up to the 2GB limit(SQL)
http://www.codeproject.com/Articles/63861/Limitations-of-SharePoint-Web-Services

If you look at the section called "Issues with Downloading Files" you will see what I am seeing.
It talks of single buffers and alternative methods but it is getting a bit beyond my expertise.
Would this webclient class be easy enough to ut in m coe and replace te SP built in webservice?
0
 
LVL 29

Accepted Solution

by:
QPR earned 0 total points
ID: 40228353
Nevermind I simply replaced all of the above code with this
 string url = "http://xx/Documents/1784.pdf";
            string localfileName = @"C:\Documents\1784.pdf";
            // Create a new WebClient instance.
            WebClient myWC = new WebClient();
            // Set the credentials
            myWC.Credentials = new NetworkCredential("x", "x", "x");
            // Download the file and save it into the local path.
            myWC.DownloadFile(url, localfileName); 

Open in new window


and it works perfectly! The limitation was SP based.
Anything I should know about the code I am using? problems/overheads/alterations?
0
 
LVL 40
ID: 41656660
Your post has led me in the right direction tough.

Isn't this enough?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A short film showing how OnPage and Connectwise integration works.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now