我试图从代码打印到网络打印机,但打印对话框中的网络打印机状态为Access denied, unable to connect
,打印按钮被禁用。但是如果从另一个应用程序打印,我可以打印到该打印机。而且,如果我从打印对话框中选择“打印到PDF”,那也可以正常工作。我只是无法打印到网络打印机。我有某种权限问题?在PrintDialog中拒绝访问网络打印机
if (File.Exists(previewDocument))
File.Delete(previewDocument);
PrintDialog printD = new PrintDialog();
printD.PageRangeSelection = PageRangeSelection.AllPages;
printD.UserPageRangeEnabled = true;
if (printD.ShowDialog() ?? false)
{
XpsDocument xpsDoc = new XpsDocument(previewDocument, FileAccess.ReadWrite);
XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
xpsWriter.Write(((IDocumentPaginatorSource)messageFlow).DocumentPaginator);
FixedDocumentSequence fixedDocSeq = xpsDoc.GetFixedDocumentSequence();
printD.PrintDocument(fixedDocSeq.DocumentPaginator, "Hello!");
}
您可能会检查您的应用程序尝试运行的上下文。如果您的应用程序在不允许打印的特权下运行,您可能会冒充应用程序上下文。 – Nair
尝试以管理员身份运行您的应用程序。 – Hozikimaru
你是从程序的内部版本还是从调试版本中获得这个错误? – Hank