C#MVC Core使用Process()打印Excel文件,PDF工作正常,但Excel仍在加载
我试图通过单击按钮通过web应用程序打印Excel(.xlsx)文件。 在我的本地服务器上一切正常,但是当我上传到IIS时,只要我点击按钮。页面将继续加载C#MVC Core使用Process()打印Excel文件,PDF工作正常,但Excel仍在加载,c#,asp.net,excel,printing,processstartinfo,C#,Asp.net,Excel,Printing,Processstartinfo,我试图通过单击按钮通过web应用程序打印Excel(.xlsx)文件。 在我的本地服务器上一切正常,但是当我上传到IIS时,只要我点击按钮。页面将继续加载 string destinationFileWord = filePath; Process print = new Process(); print.StartInfo.FileName = destinationFileWord;
string destinationFileWord = filePath;
Process print = new Process();
print.StartInfo.FileName = destinationFileWord;
print.StartInfo.UseShellExecute = true;
print.StartInfo.CreateNoWindow = true;
print.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
print.StartInfo.Verb = "PrintTo";
print.StartInfo.Arguments = Utility.GetAppSettings("PrinterSettings", "Address1");
print.StartInfo.WorkingDirectory = Path.GetDirectoryName(destinationFileWord);
print.Start();
if (print.HasExited == false)
{
print.WaitForExit(5000);
}
有人知道可能是什么问题吗
谢谢。您的问题很可能是目录映射。在服务器上,您需要使用类似这样的方法来获取当前工作目录
HttpContext.Current.Server.MapPath("~/")
本SO帖子中还发布了许多其他方法:
编辑
对于.NET Core,您需要使用IHostingEnvironment.ContentRootPath:
文档是存储在IIS工作目录中还是存储在更传统的目录中,如网络驱动器?@mr.coffee谢谢您的回复。它存储在IIS工作目录中。您好,谢谢您的回复。但我不认为这是问题所在,因为我实际上有另一个打印PDF的功能,它可以工作。我想说的是,查找filePath或fileName.HI没有问题。原来是因为Microsoft Excel,如果我将默认应用程序改为open.XLSX为LibreOffice,那么它就可以工作了。知道有什么问题吗