简体   繁体   English

如何打开在IIS上发布的应用程序的列表框中列出的文件(excel,txt,单词)?

[英]How can I open a file (excel, txt, word) listed in a ListBox in an App published on IIS?

I've developed an WebForms app in which I have files from a folder listed in a ListBox. 我开发了一个WebForms应用程序,其中包含列表框中列出的文件夹中的文件。 Running in VS2019 works fine, I double click the name of the file in the listBox and it opens but when I publish it to IIS on a Windows Server 2012, It just opens the procces on the backgroud but the file never opens. 在VS2019中运行正常,我双击列表框中的文件名将其打开,但是当我将其发布到Windows Server 2012上的IIS时,它仅在backgroud上打开了进程,但文件从未打开过。

I changed the account which the app runs to LocalSystem, Power Domain Users and nothing happens. 我将应用程序运行的帐户更改为LocalSystem,Power Domain Users,但没有任何反应。 Also I gave username and password to Process.start. 我也给了Process.start用户名和密码。

 var folder1 = @"\\BOXI\Ejecutables\CRM2\" + NumCaso_txt.Text;

                foreach (char c in "PASSWORD")
                    pwd.AppendChar(c);
                if (Directory.Exists(folder1))
                {
                    DirectoryInfo Dir = new DirectoryInfo(folder1);
                    FileInfo[] FileList = Dir.GetFiles("*.*", SearchOption.AllDirectories);
                    foreach (FileInfo FI in FileList)
                    {
                        //filesLbox.Items.Add(FI.Name + " " + FI.CreationTime);
                        if (filesLbox.SelectedIndex == i)
                        {

                            ProcessStartInfo procStart =
    new ProcessStartInfo("notepad.exe", FI.FullName);
                            procStart.UserName= "USER";
                            procStart.Domain= "DOMAIN";
                            procStart.Password = pwd;
                            procStart.UseShellExecute = false;
                            Process.Start(procStart);
                            //command.StartInfo.FileName = FI.FullName;
                            ////Process.Start(FI.FullName);
                            //command.Start();
                            break;
                        }
                        i++;
                    }
                }

If you want to open file on client computer, you need to apply some javascript which could comunicate with OS through browser. 如果要在客户端计算机上打开文件,则需要应用一些JavaScript,这些JavaScript可以通过浏览器与OS通讯。

If you want to open file on server computer, your web app must be running on user which has active GUI session. 如果要在服务器计算机上打开文件,则Web应用程序必须在具有活动GUI会话的用户上运行。 To do this, login to your server using your credentials, change application pool identity to logged in user, restart IIS and the process should open with GUI as you expected. 为此,请使用您的凭据登录到服务器,将应用程序池标识更改为已登录的用户,重新启动IIS,并且该过程应按预期的方式使用GUI打开。 If that doesn't work you can also try enabling "Allow service interact with desktop" option in IIS service configuration. 如果这样不起作用,您还可以尝试在IIS服务配置中启用“允许服务与桌面交互”选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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