Access denied to network printer in PrintDialog

I am trying to print to a network printer from the code, but the status of the network printer in the print dialog says Access denied, unable to connect , and the print button is disabled. But I can print on this printer very well if I print from another application. And, if you select "Print to PDF" in the print dialog box, this also works great. I just can't print on a network printer. Do I have any permissions?

 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!"); } 
+7
c # printing wpf
source share
2 answers

You must add this code snippet after instantiating the print dialog to find the shared network printer and print it.

 printD.PrintQueue = New PrintQueue(New PrintServer(@"\\computer server name"), "the exact name of your network printer") 

Hope this helps

0
source share

I can not comment, but I wanted to share my thoughts about your problem.

I am having a problem accessing network drives from my applications. Even when working as an administrator. I think printers are accessed in a similar way.

My problem was user account management (UAC).

Try setting the register according to this: Windows 10 and network drive

-one
source share

All Articles