I want to print PDF files on a network printer placed on my print server.
I written the code below, and it works for local printers only. When I use a network printer name, it doesn't not work.
Dim ProcessoImp As New Process
Dim VerToUse As String
VerToUse = "PrintTo"
ProcessoImp.StartInfo.CreateNoWindow = False
ProcessoImp.StartInfo.Verb = VerToUse
ProcessoImp.StartInfo.FileName = PrintFileList(i)
ProcessoImp.StartInfo.Arguments = "\\PrintServerMachine\samsung laser"
ProcessoImp.Start()
ProcessoImp.WaitForExit(10000)
ProcessoImp.CloseMainWindow()
ProcessoImp.Close()
Remember that if I use a local printer, it works perfectly, but if it's a network printer, it does not work!
What can I do to solve this problem?
More than likely, you do not have sufficient rights to print to that network printer via Visual Studio. You may try to impersonate another user or elevate current user access levels to allow printing on that network printer.
Alternatively, you should try using the printing.PrintDocument Class.
This is a duplicate question to this: Printing from ASP.NET to a network printer
Related
I have a VB WinForms app that prints PDFs using Process.Start, and it has been working fine for ages on Windows 10. Today I go to use it and get the following error message:
"No application is associated with the specified file for this operation"
Nothing has changed to cause this, I have not changed PDF Viewer or uninstalled anything. I can open a PDF by double clicking on it no problems.
I wrote a small console app to replicate the issue and prove this had nothing to do with the WinForms app:
Sub Main()
Dim pi As New Diagnostics.ProcessStartInfo
Dim url As String = "C:\PathToPDF\.pdf"
pi.FileName = url
pi.Verb = "PrintTo"
pi.CreateNoWindow = True
pi.Arguments = """Microsoft Print to PDF"""
pi.UseShellExecute = True
Console.WriteLine(url)
Diagnostics.Process.Start(pi)
Console.ReadKey()
End Sub
The above program replicates the error. I have verified that the file exists and is accessible and tried it with double slashes and single slashes, they give the same error:
"No application is associated with the specified file for this operation".
The same application is working fine on other PCs in the office.
Has anyone else had this happen, and if so how did they fix it?
My PDF viewer is PDFXChange Viewer, and it has been working fine PDFs printed using this method for years. I have not updated the program, and it says in the about page that the last installed updated was in 2016.
Regards.
If I am right, I had the same issue. Maybe you can try it in a slightly other way. I have this in my application and it works fine:
Dim myp As New Process
myp.StartInfo.FileName = filename 'Full path to pdf
myp.Start()
Good Morning,
I have been tasked with writing a program that locates the local port a MAC Address is registered to, and to do that I need to SSH and Telnet into Cisco devices and receive the output of the commands so I can parse it and decide what to do with the information.
So far I have the SSH connection and parsing done no problem thanks to Renci.SshNET. But I am having trouble with the Telnet, I set it up to use Telnetlib.dll and I know it works because I can do "show users" on the switch I'm connecting to and see that one of the vty lines are being occupied by my application. But in the application I'm writing all I get is the application freezing up, none of the buttons work, and I can't see the mouse when I hover over the window, so I'm guessing that the application isn't liking something at run-time.
The code I'm using, in VB.NET is:
Using client As TcpClient = New TcpClient(host, 23)
Dim tel As TelnetStream = New TelnetStream(client.GetStream)
Dim buff(client.ReceiveBufferSize) As Byte
Dim result As String
tel.SetRemoteMode(TelnetOption.Echo, False)
Dim exp As Expector = New Expector(tel)
exp.Expect("username: ")
exp.SendLine(username)
exp.Expect("password: ")
exp.SendLine(password)
exp.Expect(">")
tel.Read(buff, 0, buff.Length)
result = System.Text.Encoding.ASCII.GetString(buff)
MessageBox.Show(result)
End Using
Telnetlib.dll include the definitions for the Expector, SendLine, Expect, and TelnetStream.
I did some debugging and found that it freezes when it goes to execute the result = System.Text.Encoding.ASCII.GetString(buff)
command.
Thanks for any help.
I am using below code to print pdf but it is not working with windows service using network printer.
Dim gvi As New GhostscriptVersionInfo(New Version(0, 0, 0), Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "gsdll32.dll"), String.Empty, GhostscriptLicense.GPL)
Dim processor As New Ghostscript.NET.Processor.GhostscriptProcessor(gvi, True)
Dim switches As New List(Of String)()
switches.Add("-empty")
switches.Add("-dPrinted")
switches.Add("-dBATCH")
switches.Add("-dNOPAUSE")
switches.Add("-dNOSAFER")
switches.Add("-dPDFFitPage")
switches.Add("-dNumCopies=1")
switches.Add("-sDEVICE=mswinpr2")
switches.Add(Convert.ToString("-sOutputFile=%printer%") & _PrinterName)
switches.Add("-f")
switches.Add(PdfFileName)
processor.StartProcessing(switches.ToArray(), Nothing)
Is the networked printer visible to the user on the machine before you try printing ? The way that the mswinpr2 device works, it requires that the printer be visible to the user on the Windows installation its running from.
You cannot print to a printer over the network, unless that printer is mounted on your own system.
Your call seems correct. But for a network printer, you have to use
-sOutputFile="%printer%\\Hostname\Printer"
The hostname (=the machine the printer is pysically connected to) is mandatory here.
I'm troubleshooting an issue with a VB.NET app that I inherited.
The following lines execute print operation:
Me.rptShippingLabel1.PrintOptions.PrinterName = "LabelPrinter"
Me.rptShippingLabel1.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape
Me.rptShippingLabel1.PrintToPrinter(Me.txtLabelQty.Text, False, 1, 1)
There is a Zebra ZDesign TLP2844 connected to workstations via direct USB and named LabelPrinter. However, despite target printer being specified in the code, that Zebra must be set as default printer in Windows, otherwise the job would go to any other printer set as default.
What's even more frustrating is that on some computers, with exactly the same configuration jobs go to correct printer but I can't identify controllable pattern.
Any suggestions why might that be?
Reports in question are disassociated from printer in Design>Page Settings.
Look into your report. In page settings see if report is optimized for display. If yes, uncheck it. If report is optimized for displaying only, PrinterOptions enumeration is being discarded. You could still assign to Printer name property in older framework but not anymore.
Try the following code
Dim rptShippingLabel1 As New CrystalReport1
Dim PrinterSettings1 As New Printing.PrinterSettings
Dim PageSettings1 As New Printing.PageSettings
'Replace it with your printer name
PrinterSettings1.PrinterName = "Microsoft XPS Document Writer"
rptShippingLabel1.PrintToPrinter(PrinterSettings1, PageSettings1, False)
to get the printer name, don't read it from rptShippingLabel1.PrintOptions.PrinterName it will show blank. Try reading from PrinterSettings1.PrinterName.
This is tested with Crystal Reports runtime 13.0.9
I have been searching the web looking for a way to open a WORD file from a secure network folder by impersonating a user who has access. The closest I've come to finding the answer was this from 2 years ago:
Impersonating in .net (C#) & opening a file via Process.start
Here is the code that I am using. When I set the arguments = LocalFile_Test, everything works perfectly because the user is accessing the local c:\ that is has access to. But when I set arguments = RemoteFile_Test, Word opens up a blank document which is the same effect as if I put garbage in the arguments. So it appears that it cannot find the file even though when I login with the user/domain/password that I specify in the properties below, I can find that exact file name and it is not empty. Does anything jump out at you right away? I appreciate your time.
Dim LocalFile_Test As String = "C:\New.docx"
Dim RemoteFile_Test As String = "\\Server1\Apps\File\New.docx"
Dim MyStartInfo As New System.Diagnostics.ProcessStartInfo
MyStartInfo.FileName = "C:\Program Files\Microsoft Office\Office12\WINWORD.exe "
MyStartInfo.Arguments = LocalFile_Test
MyStartInfo.LoadUserProfile = True
MyStartInfo.UseShellExecute = False
MyStartInfo.UserName = "specialuser"
MyStartInfo.Domain = "mydomainname"
MyStartInfo.Password = New System.Security.SecureString()
MyStartInfo.Password.AppendChar("p"c)
MyStartInfo.Password.AppendChar("a"c)
MyStartInfo.Password.AppendChar("s"c)
MyStartInfo.Password.AppendChar("s"c)
Process.Start(MyStartInfo)
My understanding is that you are trying to get a password protected file from a server, and when you do process start, it just opens up a blank word doc. I think the error is how you are trying to get the file, I think you have to map the actual physical path of the file on the server, like
System.Web.HttpContext.Current.Server.MapPath("\\Server1\Apps\File\New.docx")
From there, I am fairly certain, you need to create network credentials for the user like
System.Net.NetworkCredential=New NetworkCredential(userName:=, password:=)
Finally, once that is done, you can either write the file, or transmit the file like so...
System.Web.HttpContext.Current.Response.TransmitFile(file name)
System.Web.HttpContext.Current.Response.WriteFile(file name)
Then,once you get the file, you can try to open it with process start.
Hope that helps, let me know if what I said doesn't work.