Solved

stringbuilder out of memory error

Posted on 2014-07-29
5
156 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

690 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