简体   繁体   中英

Open Powerpoint presentation from an ASP.NET Web app running localhost

I'm trying to execute a Powerpoint presentation from a .NET MVC Web app. I'm using the office.interopt.powerpoint libraries and everything works fine while i'm on VisualStudio. But, if i deploy the web app in a IISExpress server (not in VS), the Powerpoint application doesn't open as top-most window and it doesn't works properly, and if i deploy it in a IIS Server, the Powerpoint doesn't starts at all.

I know that the problem has something to be with the IISUSR credentials as i (as a web app) don't have the rights to execute the application.

The question is: is there a way to start a Powerpoint application as a different user using the interop libraries? I know it is possible to start a new Process as a different user with "ProcessStartInfo", but if i do that way i should execute one Powerpoint process for each presentation that i need to open and i wouldn't have access to the presentation's controls like nextSlide and so... The idea is to execute the Powerpoint once and then open, close and control many presentations.

The code that i have for now:

To start the Powerpoint app (this is executed once):

app = new Application();
app.Visible = MsoTriState.msoTrue;
app.PresentationClose += ClosePPT;
app.Activate();
app.WindowState = PpWindowState.ppWindowMinimized;
ppts = app.Presentations;

To open a new presentation:

public void LoadPPT(string pptPath)
    {
        try
        {
            //Close all opened presentations if any
            if (ppts.Count > 0)
                foreach (Presentation p in ppts)
                    p.Close();

            //Open new presentation
            ppt = ppts.Open(pptPath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);

            SlideShowSettings sss = ppt.SlideShowSettings;
            sss.Run();
            while (app.SlideShowWindows.Count <= 0) ;
            SlideShowWindow ssw = ppt.SlideShowWindow;
            ssw.Activate();

            //if (!SetWindowPos((IntPtr)ssw.HWND, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW))
            //{
            //    int error = Marshal.GetLastWin32Error();
            //    NLog.LogManager.GetCurrentClassLogger().Debug("Error " + error);
            //}

            ssv = ssw.View;
        }
        catch (Exception e)
        {
            NLog.LogManager.GetCurrentClassLogger().Debug("Excepcion en PPT. " + e.Message);
            while (e.InnerException != null)
            {
                NLog.LogManager.GetCurrentClassLogger().Debug("INNER. " + e.InnerException.Message);
                e = e.InnerException;
            }
        }
    }

As you can see, i've also tried to set the window of the slideshow presentation at top-most position using the Win32 "SetWindowPos", but with the same result.

I'm trying to execute a Powerpoint presentation from a .NET MVC Web app. I'm using the office.interopt.powerpoint libraries

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.

You may consider using any third-party components designed for the server-side execution (ASP.NET controls that can host PowerPoint presentations).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM