Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello everyone, I am trying to open a pdf file using below code:
XML
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>");
        }
    }

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
Posted
Comments
Sergey Alexandrovich Kryukov 3-Nov-15 17:44pm    
Adobe Acrobat reader? On server side?! of what server? Why?!
It does not seem to make any sense. What are you trying to achieve?
—SA

1 solution

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.

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


This assumes Acrobat is the registers program for PDF files.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900