Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2007

Tip: Looking for answers? Try searching our database.

System.OutOfMemoryException while Creating PDF files

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Aryan - 23 Oct 2007 11:08 GMT
Hi,

I am using C# with framework 2.0 and creating PDF files on-fly, along
with this I am using Windows 2003 Server.

I am using Byte[] to take the data input and then save into pdf format
on harddrive location.

Now after creating few successful pdf files, I am getting
"System.OutOfMemoryException".

Is this problem coming because of large data is been sent to Byte[] to
create PDF file or something else could be the cause.

If so, then how to resolve this issue??

Thanks in Advance,

Manoj
Kevin Spencer - 23 Oct 2007 11:58 GMT
Don't read the entire file into a byte array. Instead, process it in
manageable chunks, reading a smaller chunk of the file at a time.

Signature

HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP

> Hi,
>
[quoted text clipped - 15 lines]
>
> Manoj
Aryan - 23 Oct 2007 14:01 GMT
Keven, Thanks for prompt reply.

Here is the sample code snippet.

I am using SQLReport Server 2005 to get the data.

Byte[] results;
ReportExecutionService rsExec;
results = rsExec.Render(format, deviceInfo,
                       out extension, out encode,
                       out mimeType, out warnings, out streamIDs);

SavePDF(results, filename); // calling SavePDF method to save the
result array output in PDF form.

private bool SavePDF(Byte[] results, string fileName)
       {
           try
           {

               using (FileStream stream = File.OpenWrite(fileName))
               {
                   stream.Write(results, 0, results.Length);
                   stream.Close();
                   stream.Dispose();
               }

               return true;
           }
           catch(Exception ex)
           {
               throw;
           }
       }

Now,
1> If I get large stream from ReportExecutionService then how to split
it in chunks and create a pdf file(say pdf has something around 3000 /
5000 pages in it)

Thanks in Advance.
Manoj

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.