[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Error exporting Slides from PowerPoint using VB.net

Posted on 2009-04-07
6
Medium Priority
?
507 Views
Last Modified: 2012-05-06
For some reason PowerPoint has started crashing with the following code but has been working for over a year. Any ideas?
Dim DestFile As String = "c:\temp\"
 
        If Not IO.Directory.Exists(DestFile) Then
            IO.Directory.CreateDirectory(DestFile)
        End If
 
 
        Dim objApp As New PowerPointMe.Application
 
 
 
        objApp.Visible = MsoTriState.msoTrue
        objApp.Presentations.Open(FileStr, MsoTriState.msoFalse, MsoTriState.msoCTrue, MsoTriState.msoCTrue)
        objApp.Assistant.On = False
 
        objApp.Presentations(1).SaveAs(DestFile & "Benefit_" & BenefitID & ".bmp", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsBMP, MsoTriState.msoCTrue)
 
        Dim PresentationByte() As Byte = Nothing
        Dim FileArray(objApp.Presentations(1).Slides.Count - 1) As Object
        Dim i As Integer = 1
 
        For i = 1 To objApp.Presentations(1).Slides.Count
            Dim SlideFileStr As String = DestFile & "Benefit_" & BenefitID & "\Slide" & i & ".bmp"
 
            Dim FS As IO.FileStream = IO.File.Open(SlideFileStr, IO.FileMode.Open)
            ReDim PresentationByte(FS.Length - 1)
            FS.Read(PresentationByte, 0, FS.Length - 1)
 
            FS.Close()
 
            'Save File into array, the array will be saved to the db and pulled back out on the client
            FileArray(i - 1) = PresentationByte
 
        Next
 
        Try
            objApp.ActiveWindow.Close()
        Catch
 
        End Try
        Try
            If objApp.Presentations.Count > 0 Then
                objApp.Presentations(1).Close()
            End If
        Catch ex As Exception
            If Debugger.IsAttached Then Stop
        End Try
        Try
            objApp.Quit()
        Catch ex As Exception
            If Debugger.IsAttached Then Stop
        End Try
 
 
        GC.Collect()
 
        Return ConvertObjectToBytes(FileArray)

Open in new window

0
Comment
Question by:jmarbutt
[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
  • 4
6 Comments
 
LVL 21

Accepted Solution

by:
GlennaShaw earned 1000 total points
ID: 24089076
Did you upgrade to 2007?
I'm not that good with VB, so I suggest you'll get a quicker answer here:
https://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public.powerpoint&lang=en&cr=US
However, make sure you specify which version of PowerPoint you're using and exactly what you're trying to do (are you exporting the images into a database?)
0
 
LVL 59

Assisted Solution

by:Chris Bottomley
Chris Bottomley earned 1000 total points
ID: 24089413
I'm not that aware of .net but as Glenna pointed out a change in version could explain teh sudden change.

Which line is failing and with what error code ... we may be able to rationalise it out.

Chris
0
 
LVL 2

Author Comment

by:jmarbutt
ID: 24090671
Yes it is 2007 but we have been using it a while with out a problem.

It is throwing an error in the when we start to exit the function, it is almost like it doesn't want to let go of the reference and/or the GC is not disposing it correctly.
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 2

Author Comment

by:jmarbutt
ID: 24090924
The error I get is:


ContextSwitchDeadlock was detected
Message: The CLR has been unable to transition from COM context 0x1bc5bbd0 to COM context 0x1bc5be20 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

Open in new window

0
 
LVL 2

Author Closing Comment

by:jmarbutt
ID: 31567554
This actually ended up being something completely different. Thanks for your help, I still rewarded the points
0
 
LVL 2

Author Comment

by:jmarbutt
ID: 24091459
There was another section of my code that was actually throwing the problem, basically the SQL command was timing out only on certain powerpoints. So not even a valid question
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

650 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