none
Sending raw data to a label printer from Asp.Net code-behind RRS feed

  • Question

  • I have a text block containing CPL commands which I need to send to a number of label printers, in it's raw format.

    The action is initiated via an ASP.Net page, the printers and drivers will all be configured on the web server.  My preference is to just send the raw text to a named printer from the code-behind, as these are fairly small sets of data and the user will probably be walking away to collect the labels as soon as they hit the button, so I don't have concerns about a slow response to the user.

    If this is a really bad idea, I could queue the print jobs for a background service to handle, but I hope that is not necessary.

    Is there a suitable .Net library feature for sending this raw data to a printer, or does the old old example of P/Invoke to win32 methods still remain the only way to do this?  The System.Printing library classes all carry warnings that they should only be used from a WPF UI environment and are not suitable for use in ASP.Net.  What is suitable?

    p.s, yes I have searched; many hours of searching has led me in circles, chasing 8 year old discussions, wondering what all the deleted Microsoft kb articles used to tell us, and trying to find the correct modern way to do this.


    Thursday, February 8, 2018 8:07 PM

All replies

  • If the printer is attached to COM/LPT port, the normal way is to open a handle using CreateFile() API, pass it to FileStream, and proceed as if you're copying file.

    Here is an example.

    Friday, February 9, 2018 1:18 AM
  • Hi Les Ferguson,

    Thank you for posting here.

    For your question is more related to ASP.NET, you could post a new thread in ASP.NET forum for suitable support.

    The CLR Forum discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection. Also discuss all the other Microsoft libraries that are built on or extend the .NET Framework, including Managed Extensibility Framework (MEF), Charting Controls, CardSpace, Windows Identity Foundation (WIF), Point of Sale (POS), Transactions.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, February 9, 2018 7:23 AM