无法在服务器上执行AcroRd32.exe [英] Unable to execute AcroRd32.exe on server

查看:209
本文介绍了无法在服务器上执行AcroRd32.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在尝试使用以下代码打开pdf文件:

Hello everyone, I am trying to open a pdf file using below code:

protected void Openfile_Click(object sender, EventArgs e)
    {
        try
        {
            var list = new List<string>();
            Button btn = (Button)(sender);
            string part_no = btn.CommandArgument;
            bool fileExist;
            var adobePath       = Registry.GetValue(@"HKEY_CLASSES_ROOT\Software\Adobe\Acrobat\Exe", string.Empty, string.Empty);
            var fileToSearch = "6-65-JX9011B";
                        bool notFound       = true;
            bool adobeFound     = false;

            Process myProcess = new System.Diagnostics.Process();
                        if (adobePath != null)
            {
                Response.Write("<script>alert('found adobe')</script>");
                DirSearch(list, "//SERVERNAME/wwwroot/IntranetTools/manuGangBeta/");
                adobeFound = true;
                foreach (var file in list)
                {
                    fileExist = file.Contains(fileToSearch);
                    if (fileExist)
                    {
                        try
                        {
                            Response.Write("<script>alert('file found going to open')</script>");
                            myProcess.StartInfo.FileName = "AcroRd32.exe";
                            myProcess.StartInfo.Arguments = string.Format("/A \"page=1=OpenActions\" \"{0}\"", file);
                            myProcess.StartInfo.CreateNoWindow = true;
                            myProcess.StartInfo.UseShellExecute = true;
                            myProcess.Start();
                            notFound = false;
                            break;
                        }
                        catch(Exception)
                        {
                            Response.Write("<script>alert('Unable to Start Acrobat Reader.')</script>");
                        }
                    }
                }
            }
            else
            {
                Response.Write("<script>alert('Please install Adobe Reader to view this file.')</script>");
            }
            if (notFound && adobeFound)
            {
                Response.Write("<script>alert('There is no production file available to view for this Order. Please create a new file and it will be availble for view here.')</script>");
            }
        }
        catch (Exception)
        {
            Response.Write("<script>alert('An error occurred while processing your request in Openfile_Click.')</script>");
        }
    }



以上代码适用于本地系统(在独立应用程序中),但当我尝试从服务器打开pdf文件时,它没有做任何事情。早些时候我们没有adobe那边,但安装后说我们有adobe但仍然没有打开。我的问题是,我们可以在服务器上启动进程吗?我正在考虑创建Windows服务,以便我们可以为该服务授予权限以启动进程。任何想法都将受到高度赞赏



谢谢,

加里


the above code works well on local system(in standalone application) but when I tries to open pdf file from server, it is not doing anything. Earlier we were not having adobe over there, but after installing it saying that we have adobe but still not opening. MY question is that can we start a process on server? I am thinking to create windows service so that we can give permissions to that service to start a process. Any idea will be highly appreciated

Thanks,
Gary

推荐答案

这听起来像是这个问题的重复:



http://stackoverflow.com/questions/9024614/system-diagnostics-process-start-doesnt-work-in-the-web-server [< a href =http://stackoverflow.com/questions/9024614/system-diagnostics-process-start-doesnt-work-in-the-web-servertarget =_ blanktitle =New Window> ^ ]



您可能遇到线程模型问题。



将StartInfo.UseShellExecute设置为true需要STA线程。



https://msdn.microsoft.com/en-us/library/53ezey2s%28v=vs.110%29.aspx [ ^ ]



可能是您的服务器进程没有AcroRd32.exe的路径。尝试使用开始或打开动词,并将PDF作为文件名。



This sounds like a duplicate of this question:

http://stackoverflow.com/questions/9024614/system-diagnostics-process-start-doesnt-work-in-the-web-server[^]

You may have a threading model problem.

Setting StartInfo.UseShellExecute to true requires an STA thread.

https://msdn.microsoft.com/en-us/library/53ezey2s%28v=vs.110%29.aspx[^]

It may be your server process does not have the path to AcroRd32.exe. Trying using the "start" or "open" verbs with the PDF as the file name.

myProcess.StartInfo.Verb = "open";
myProcess.StartInfo.FileName = file;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.UseShellExecute = true;
myProcess.Start();





这假定Acrobat是PDF文件的寄存器程序。



This assumes Acrobat is the registers program for PDF files.


这篇关于无法在服务器上执行AcroRd32.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆