I just introduced a new feature in one of my bots that allows the user to select what printer they would like to use. If the user selects a printer that has spaces in it the bot errors out and says the following.
A screenshot of the printer is below it is called “\Hcs05rf01\KONICA MINOLTA PRINT ROOM”
What can I do to stop this error from happening?
Main.xaml (14.6 KB)
ppr
(Peter Preuss)
August 28, 2023, 5:06pm
2
Give a try by Surrounding the printername
String.Format("Start-Process '{0}' '-Verb PrintTo '{1}' ", CurrentFile.FullName, MyPrinterName )
Your code does work when there are no spaces
Is it because I need the printername in Quotes and my variable isn’t doing that?
Anil_G
(Anil Gorthi)
August 28, 2023, 8:16pm
5
@Grey_Angel
You can add the quotes to the string like this
Str = """" + str + """"
This will add double wuotes to the string here str is the string variable
Cheers
ppr
(Peter Preuss)
August 28, 2023, 8:29pm
6
Grey_Angel:
printername in Quotes
we started with single quotes and can use double quotes by escaping with another double quote as mentioned by @Anil_G
here we can use the String.Format method as introduced above and it could look like this:
String.Format("Start-Process '{0}' '-Verb PrintTo ""{1}"" ", CurrentFile.FullName, MyPrinterName )
or with ending / concatenating, where do see 3 double quotes (1 for the escaping, 1 the doublequote, 1 for the string end / start
However just explore what is needed by prototyping the hardcoded command, then port it to the preferred option
This worked great My final script was
String.Format(“Start-Process '” + CurrentFile.FullName + “’ -Verb PrintTo " + “””" + MyPrinterName + “”“”)
system
(system)
Closed
September 1, 2023, 12:52pm
8
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.