web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Send text to printer

(0) ShareShare
ReportReport
Posted on by 465

I'm trying to print a label on our Zebra printer with ZPL (Zebra Print Language). The printer has been added as a generic text printer and I'm trying to use a StreamWriter object to send the text to the printer. But I get an error "could not create CLRObject". Code looks like this:


StreamWriter sw;

;

perm.assert();
sw = new System.IO.StreamWriter(@"\\server\printer");
sw.WriteLine('Test');
sw.Flush();
sw.Close();
sw.Dispose();
CodeAccessPermission::revertAssert();

I also tried to write the text to a file and the move it to the print which worked.

StreamWriter sw;
FileName fileName = "file.txt";

;

perm.assert();
sw = new System.IO.StreamWriter(fileName);
sw.WriteLine('Test');
sw.Flush();
sw.Close();
sw.Dispose();

WinApi::move(fileName, @"\\server\printer");
CodeAccessPermission::revertAssert();

Any ideas?

*This post is locked for comments

I have the same question (0)
  • aouwendijk Profile Picture
    on at

    In AX 4.0 we are using WinApi::copyFile from within a RDP session. Should work in 2009 but I was not able to test it.

          //Print label if printer is specified (copy to shared printer name via UNC)

           if (UNCPrinter)

           {

               err = WinApi::copyFile(filename, UNCPrinter);

           }

  • HenkeNord Profile Picture
    465 on at

    Thanks for the answer.

    Maybe I wasn't clear about the problem. The move-command works but I don't wan't to mess with files. I would like to send it directly to the printer.

  • aouwendijk Profile Picture
    on at

    OK, You must make the trade-off if you let create barcodes by the printer of by the printer driver. If you don't need barcodes just use printer divers for your Zebra printer. If you want accurate barcodes on your labels, use ZPL and let the printer create the barcode.

  • HenkeNord Profile Picture
    465 on at

    You mean it's only possible to send a file to the printer if I want the printer to take care of the creation.

    However it's possible to print the zpl-codes from notepad directly to the printer, why can't AX send plain text to a network printer?

  • Suggested answer
    keoma Profile Picture
    32,729 on at

    hi,

    the first attempt can not work (no appropriate constructor).

    check msdn.microsoft.com/.../system.io.streamwriter.streamwriter(v=vs.110).aspx

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans