title: How do you print from ASP.NET CORE web app?
body: <p>I'm searching for a way to print a jpeg to the default printer on page post of my asp.net core razorpages web app (the user shouldn't have to navigate the print window, it should automatically print when the page is submitted).  I've tried client-side printing with windows.print(), but this isn't suitable because I'm trying to print from a data Url for a jpeg. For server-side printing, Microsoft docs says <code>System.Drawing.Printing</code> should only be used for windows forms and directs to <code>System.Printing</code>. However, <code>using System.Printing</code> is not recognized in the page model, but <code>using System.Drawing.Printing</code> is, and Microsoft docs also says &quot;Classes within the <code>System.Printing</code> namespace are not supported for use within a Windows service or ASP.NET application or service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.&quot; <br>What is the namespace for an asp.net web application then?<br><br>I've been trying the methods suggested by other users, but I can't get the below code to work. The error message says the filename is too long (<code>Visitor.Badge</code> is a data Url), and when I change the file name to a local file just to test the method, the error message says it can't find the file (even though the path is correct for that file). Is printing a jpeg from a data Url even possible? Is there a different way I should be printing or is this just a syntax issue?
  I'm a novice at asp.net, so I appreciate the help!</p>
  <pre><code>private void Print();
  {
      ProcessStartInfo info = new ProcessStartInfo();
      info.Verb = &quot;print&quot;;
      info.FileName = Visitor.Badge;
      //Testing method with local file:
      //info.FileName = @&quot;C:\Users\JohnSmith\Documents\ExampleFile.jpeg&quot;;
      info.CreateNoWindow = true;
      info.WindowStyle = ProcessWindowStyle.Hidden;
  
      Process p = new Process();
      p.StartInfo = info;
      p.Start();
  
      p.WaitForInputIdle();
      System.Threading.Thread.Sleep(3000);
      if (false == p.CloseMainWindow())
          p.Kill();
  }
  </code></pre>