Hi All,
in XSharp console app this command work ok
File.Copy(xPathFile,"LPT3")
in XSharp service return error: System.IO.FileNotFoundException: Could not find file 'LPT3'.
LPT 3 is shared USB Pos printer (using Loopback Adapter)
Juraj
XSharp service error
- lumberjack
- Posts: 727
- Joined: Fri Sep 25, 2015 3:11 pm
- Location: South Africa
XSharp service error
Hi Juraj,
Try also with the third parameter, TRUE/FALSE:
Good luck!
The closest answer I could get:hsc wrote: in XSharp console app this command work okin XSharp service return error: System.IO.FileNotFoundException: Could not find file 'LPT3'.Code: Select all
File.Copy(xPathFile,"LPT3")
LPT 3 is shared USB Pos printer (using Loopback Adapter)
For network shared printers you need to specify the printer name.For local printers...
File.Copy("xxx.txt","LPT1")
For network printers
File.Copy("xxx.txt","serverprintername")
Try also with the third parameter, TRUE/FALSE:
Code: Select all
File.Copy("xxx.txt","serverprintername",TRUE)
File.Copy("xxx.txt","serverprintername", FALSE)
______________________
Johan Nel
Boshof, South Africa
Johan Nel
Boshof, South Africa
XSharp service error
Hi Johan,
thanks for advice.
The printer is connected on the same computer in which running the service app. If I enter a network name,(loacalhostEpson) the service will not report an error, but the printer will not print anything.
I think the problem is that the file.copy command is in service
Juraj
thanks for advice.
The printer is connected on the same computer in which running the service app. If I enter a network name,(loacalhostEpson) the service will not report an error, but the printer will not print anything.
I think the problem is that the file.copy command is in service
Juraj
- lumberjack
- Posts: 727
- Joined: Fri Sep 25, 2015 3:11 pm
- Location: South Africa
XSharp service error
Hi Juraj,
Ok understand, hopefully Robert or Chris have a better solution. Otherwise you might have to convert some of the examples on MSDN, codeproject, csharpcorner etc. Just google, there are plenty of examples all indicating to use the MS recommendation.
Regards and sorry that I could not help,
Ok understand, hopefully Robert or Chris have a better solution. Otherwise you might have to convert some of the examples on MSDN, codeproject, csharpcorner etc. Just google, there are plenty of examples all indicating to use the MS recommendation.
Regards and sorry that I could not help,
______________________
Johan Nel
Boshof, South Africa
Johan Nel
Boshof, South Africa
XSharp service error
Juraj,
I think the link between LPT3 and the printer port is user specific. Another user (and the System user) will not inherit your settings in this area.
If you create the link from your service app (try to run NET USE LPT3 serverprinter from the app) then it might work.
Robert
I think the link between LPT3 and the printer port is user specific. Another user (and the System user) will not inherit your settings in this area.
If you create the link from your service app (try to run NET USE LPT3 serverprinter from the app) then it might work.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
- lumberjack
- Posts: 727
- Joined: Fri Sep 25, 2015 3:11 pm
- Location: South Africa
XSharp service error
Hi Juraj,
Found this, not tested, sorry c#:
Should not be too difficult to convert into X#, or just compile it as is an consume in your service.
HTH,
Found this, not tested, sorry c#:
Code: Select all
using Microsoft.Win32.SafeHandles;
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace YourNamespace
{
public static class Print2LPT
{
[DllImport("kernel32.dll", SetLastError = true)]
static extern SafeFileHandle CreateFile(string lpFileName, FileAccess dwDesiredAccess,uint dwShareMode, IntPtr lpSecurityAttributes, FileMode dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
public static bool Print()
{
string nl = Convert.ToChar(13).ToString() + Convert.ToChar(10).ToString();
bool IsConnected= false;
string sampleText ="Hello World!" + nl +
"Enjoy Printing...";
try
{
Byte[] buffer = new byte[sampleText.Length];
buffer = System.Text.Encoding.ASCII.GetBytes(sampleText);
SafeFileHandle fh = CreateFile("LPT1:", FileAccess.Write, 0, IntPtr.Zero, FileMode.OpenOrCreate, 0, IntPtr.Zero);
if (!fh.IsInvalid)
{
IsConnected= true;
FileStream lpt1 = new FileStream(fh,FileAccess.ReadWrite);
lpt1.Write(buffer, 0, buffer.Length);
lpt1.Close();
}
}
catch (Exception ex)
{
string message = ex.Message;
}
return IsConnected;
}
}
}
HTH,
______________________
Johan Nel
Boshof, South Africa
Johan Nel
Boshof, South Africa
XSharp service error
Hi Johan and Rober,
Robert's advice was right, when I run NET USE LPT3..... from service app, command File.copy work OK.
Similar problems also have a command Directory.Getrfiles command from a shared directory on another PC
Command: Directory.GetFiles("OnotherPCSharedDir","Tab*.TXT")
this command in console app work ok, in service app return:
Error: System.IO.IOException: The specified server cannot perform the requested
Juraj
Robert's advice was right, when I run NET USE LPT3..... from service app, command File.copy work OK.
Similar problems also have a command Directory.Getrfiles command from a shared directory on another PC
Command: Directory.GetFiles("OnotherPCSharedDir","Tab*.TXT")
this command in console app work ok, in service app return:
Error: System.IO.IOException: The specified server cannot perform the requested
Juraj
XSharp service error
this is complete error message:
Error: System.IO.IOException: The specified server cannot perform the requested operation.
Juraj
Error: System.IO.IOException: The specified server cannot perform the requested operation.
Juraj
XSharp service error
Hi Juraj,
a service is a completely different beast - many things that work in a normal Windows application will not work in services.
Specially when it comes to network connections a service is very limited, mostly for security reasons.
That has nothing to do with VO or X#or whatever tool you are using, but with how your service is configured and with Microsofts security measures.
A service running under the system account cannot access networked ressources, for example. To have a service access remote ressources, you have to create a proper user with the correct network access. Mappings will also not work, only UNC paths.
Wolfgang
a service is a completely different beast - many things that work in a normal Windows application will not work in services.
Specially when it comes to network connections a service is very limited, mostly for security reasons.
That has nothing to do with VO or X#or whatever tool you are using, but with how your service is configured and with Microsofts security measures.
A service running under the system account cannot access networked ressources, for example. To have a service access remote ressources, you have to create a proper user with the correct network access. Mappings will also not work, only UNC paths.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it