Open powerpoint presentation from a Windows C# form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tastypotato
    New Member
    • Oct 2008
    • 7

    Open powerpoint presentation from a Windows C# form

    I have the same exact question as Josep in this thread: http://bytes.com/forum/thread272940.ht ml except when I try and compile the program I get a few errors (6 of them to be exact)

    They are as follows.

    C:\Documents and Settings\Tom\De sktop\Work\High School US\HighSchool US\HighSchool US\Form1.cs(129 ,45): error CS0234: The type or namespace name 'Core' does not exist in the namespace 'Microsoft.Offi ce' (are you missing an assembly reference?)
    C:\Documents and Settings\Tom\De sktop\Work\High School US\HighSchool US\HighSchool US\Form1.cs(134 ,13): error CS0103: The name 'objPres' does not exist in the current context
    C:\Documents and Settings\Tom\De sktop\Work\High School US\HighSchool US\HighSchool US\Form1.cs(134 ,48): error CS0103: The name 'MsoTriState' does not exist in the current context
    C:\Documents and Settings\Tom\De sktop\Work\High School US\HighSchool US\HighSchool US\Form1.cs(135 ,13): error CS0103: The name 'MsoTriState' does not exist in the current context
    C:\Documents and Settings\Tom\De sktop\Work\High School US\HighSchool US\HighSchool US\Form1.cs(135 ,34): error CS0103: The name 'MsoTriState' does not exist in the current context

    Now, please take in mind that I am still learning C# and know a little bit about C++, so I will be able to get some of it but I might need a more dumbed down version.

    Also, since this code is not exactly something I want to post right up on the board, if you think you can help me please let me know. :)

    -Tom

    EDIT: Here's the snippet of code that I copy pasted from the old thread

  • joedeene
    Contributor
    • Jul 2008
    • 579

    #2
    perhaps google.com help you greatly in your situation..."ty pe in how to open a powerpoint in c#"

    joedeene

    Comment

    • Tastypotato
      New Member
      • Oct 2008
      • 7

      #3
      Originally posted by joedeene
      perhaps google.com help you greatly in your situation..."ty pe in how to open a powerpoint in c#"

      joedeene
      Nope, it doesn't.. Leads me back to here, and other sites that link to that old thread.

      I need help with the errors that it's giving me. :(

      Comment

      • joedeene
        Contributor
        • Jul 2008
        • 579

        #4
        Originally posted by Tastypotato
        Nope, it doesn't.. Leads me back to here, and other sites that link to that old thread.

        I need help with the errors that it's giving me. :(
        try exploring areas of this MSDN site. or looking up tutorials on the Powerpoint.Appl ication class?

        joedeene

        Comment

        • Tastypotato
          New Member
          • Oct 2008
          • 7

          #5
          Well, first off, I'm not using Visual Basic, second of all, I don't even think you looked over these errors.. I may be a beginner, but I know this is a step in the wrong direction... I appreciate that you're trying to help, but do you even know how to do this..?


          EDIT: I do not have a Microsoft.Offic e.Core reference.. Bleh, let me see if I can't fix that.

          Comment

          • Curtis Rutland
            Recognized Expert Specialist
            • Apr 2008
            • 3264

            #6
            I think you may need to add a reference to Microsoft.Offic e.Core, but I can't be sure, since I don't have Visual Studio in front of me right now.

            See if you can do that and let me know.

            Edit, seems like you beat me to the punch. Let us know how it goes.

            Now, let's try to keep it polite, fellas. joedeene is trying to help, and if the help isn't working, just say it didn't work and ask for more help. OK?

            Mod.

            Comment

            • Tastypotato
              New Member
              • Oct 2008
              • 7

              #7
              Originally posted by insertAlias
              I think you may need to add a reference to Microsoft.Offic e.Core, but I can't be sure, since I don't have Visual Studio in front of me right now.

              See if you can do that and let me know.

              Edit, seems like you beat me to the punch. Let us know how it goes.

              Now, let's try to keep it polite, fellas. joedeene is trying to help, and if the help isn't working, just say it didn't work and ask for more help. OK?

              Mod.
              Sorry, I've been working on this for a week and since I've hit this brick wall my boss has been heckling me.. Well, I'm sure how you all know how it goes. :/

              I apologize.

              And yes, I got the office core file in there now but instead of giving me the whole core not being there I get:
              C:\Documents and Settings\Tom\De sktop\Work\High School US\HighSchool US\HighSchool US\Form1.cs(130 ,28): error CS0029: Cannot implicitly convert type 'Microsoft.Offi ce.Core.MsoTriS tate [c:\Documents and Settings\Tom\De sktop\Work\High School US\HighSchool US\HighSchool US\obj\Debug\In terop.Microsoft .Office.Core.dl l]' to 'Microsoft.Offi ce.Core.MsoTriS tate []'

              Man.. that's a doozy.

              I'm reading up on error CS0029 right now, but here is the offending line of code:
              oPPT.Visible = Microsoft.Offic e.Core.MsoTriSt ate.msoTrue;


              EDIT:
              I'm reading up here: http://msdn.microsoft.com/en-us/libr...x5(VS.71).aspx but... their examples are way more simple than the ones that I've got going on here, and well.. I'm lost again. xD

              Comment

              • Curtis Rutland
                Recognized Expert Specialist
                • Apr 2008
                • 3264

                #8
                That's really wierd...it's expecting an explicit cast, but it seems to be the same datatype. Try explicitly casting it anyway.

                Put the datatype in parenthesis behind it, or right after it say "as <datatype>" replacing <datatype> with whatever it was.

                Interop is always a pain, IMHO.

                Comment

                • Tastypotato
                  New Member
                  • Oct 2008
                  • 7

                  #9
                  I've started to figure that out. :/

                  Now I've got "The as operator must be used with a reference type or a nullable type (Microsoft.Offi ce.Core.MsoTriS tate is a non nullable value type)"

                  Bleh.

                  This is what I've got in the code right now on that line that's causing the error:
                  oPPT.Visible = Microsoft.Offic e.Core.MsoTriSt ate.msoTrue as Microsoft.Offic e.Core.MsoTriSt ate;

                  Also: I tried oPPT.Visible = Microsoft.Offic e.Core.MsoTriSt ate.msoTrue as <Microsoft.Offi ce.Core.MsoTriS tate>;
                  just for the heck of it, and that didn't work either.
                  ):

                  EDIT:

                  error CS0012: The type 'Microsoft.Offi ce.Core.MsoTriS tate' is defined in an assembly that is not referenced. You must add a reference to assembly 'office, Version=11.0.0. 0, Culture=neutral , PublicKeyToken= 71e9bce111e9429 c'.


                  the oPPT.Visible on that same line gives me this error code as well, do you think that the fact that PowerPoint.Appl icationClass() does not have a Visible class?

                  Comment

                  • Curtis Rutland
                    Recognized Expert Specialist
                    • Apr 2008
                    • 3264

                    #10
                    OK, I read something weird on the internet, but it's worth a shot. Try removing the reference to Powerpoint, and then adding it again. Then see if it builds.

                    Also try the explicit cast like this:
                    Code:
                    oPPT.Visible = (Microsoft.Office.Core.MsoTriState)Microsoft.Office.Core.MsoTriState.msoTrue;
                    There shouldn't be space in there, so just ignore it.

                    Comment

                    • Tastypotato
                      New Member
                      • Oct 2008
                      • 7

                      #11
                      Hm, at first I thought it was going to work and then those 6 errors popped up again... Is there another way to go about doing this without having to use interop? It seems like it's too much of a hassle. :/

                      Comment

                      • Curtis Rutland
                        Recognized Expert Specialist
                        • Apr 2008
                        • 3264

                        #12
                        Well, there's always
                        Code:
                        System.Diagnostics.Process.Start("pathToFileToStart");
                        That will just open a powerpoint application, if you point it to the .ppt file.

                        Comment

                        • joedeene
                          Contributor
                          • Jul 2008
                          • 579

                          #13
                          ya, i was thinking of that too, but it opens up MS Office Powerpoint and then you have to click view slide show or something to watch it....unless there's a command you can send to it, to start the slideshow as soon as it opens ?

                          joedeene

                          Comment

                          • Tastypotato
                            New Member
                            • Oct 2008
                            • 7

                            #14
                            Originally posted by insertAlias
                            Well, there's always
                            Code:
                            System.Diagnostics.Process.Start("pathToFileToStart");
                            That will just open a powerpoint application, if you point it to the .ppt file.
                            It's not as flashy, but I guess that will have to do as seeing as the interop doesn't really want to work in the program.

                            Comment

                            Working...