The code you've shown is executing
on the server.
It might
appear to work when you debug your code within Visual Studio, but that's only because the server and the client are the same machine in that specific instance.
As soon as you deploy your code to a real server, it will break. At best, you'll get an exception telling you that the current process is not interactive. At worst, the dialog box will appear on the server, where nobody will ever see it, and your code will hang waiting for someone to press a button on an invisible dialog box.
If you want to print the current HTML document, you'll need to use Javascript running on the client, and call the
Window.print()[
^] method.
If you want to print something other than HTML, then you're going to have to let the user download the file and print it themselves. There is no way to initiate printing an external file from Javascript.