# Thursday, 28 October 2010

ASP.NET applications run under an account with limited privileges that doesn’t have the right to connect to a network printer.  The normal answer for this is to give rights to the user running your application or impersonate a user during execution that does have the rights.

We found another way that doesn’t require changing the user or privileges of the existing account that ASP.NET apps run under.

I can hear someone asking “Why would you want to do this anyway?  Can’t the end user choose a printer?”  There might be situations where this isn’t sufficient enough.  We had to control the printer line by line in order to print on the form that is being used and a particular printer had to be used.  

We added the network printer as a printer on the server where our app was running.  When we setup the printer we chose local not networked but then on the options to use a printer port we didn’t use LPT1.  Instead we created a new port with the IP address of the device.  In our code we then call the printer by the name we gave it on our server.

port

printer 

The PrintDocument class in the .NET Framework allows for control of a printer.

VB Version:

Public Class SpecialReportPrintJob 
  Inherits Printing.PrintDocument 
 
Protected Overrides Sub OnBeginPrint(ByVal ev as Printing.PrintEventArgs) 
  MyBase.OnBeginPrint(ev) 
 
  Me.PrinterSettings.PrinterName = "SCLaser2" 
 
  'setup rest of stuff.... 
End Sub   
End Class 
'And we then call it like so 
Dim printSpecialReport as new SpecialReportPrintJob() 
printSpecialReport.Print()
C# Version:
public class SpecialReportPrintJob : Printing.PrintDocument
{

    protected override void OnBeginPrint(Printing.PrintEventArgs ev)
    {
        base.OnBeginPrint(ev);

        this.PrinterSettings.PrinterName = "SCLaser2";

        //setup rest of stuff.... 
    }
}
//And we then call it like so
SpecialReportPrintJob printSpecialReport = new SpecialReportPrintJob();
printSpecialReport.Print();

PrintDocument is pretty powerful.  It can control just about anything for your printer.  We passed in a text file of our data to print and our code setup the x, y coordinates of each item as it related to where on the form it needed to be.

All this without having to muck around with permissions.  Always a good thing!

Happy Coding!

Posted 10.28.2010  #    Comments [0]  | 
# Wednesday, 29 September 2010

Our team is working on a UI facelift for an intranet application that helps drive our internal yearly budgetary process.  During the beginning stages of the development of this effort we hired a new webmaster and we invited him to the effort to help give our UI a nice finish with all the CSS goodness and jQuery goodies.

During this process our webmaster began using some CSS3 magic to make things look nice.  As most good webmasters and designers firefox was used as the start of the design.  For our intranet however, IE is king and we have a mix of IE7 - 8 and they don’t support many CSS3 features.  Our webmaster turned to CSS3Pie.  I had no idea about this little gem and he had just recently come across it.  Download it, write your CSS3 and apply PIE and magically Internet Explorer renders CSS3.

As an example of what it can do, what if you wanted to apply a nice rounded edge to an element.  Fire up VS 2010 and start a new web forms project.  Let’s round the edges of the bottom of the border in the default page.

image

Let’s edit the page element in the site.css to get this going.

.page
{
    width: 960px;
    background-color: #fff;
    margin: 20px auto 0px auto;
    border: 1px solid #496077;
    border-radius: 0px 0px 10px 10px;
    -moz-border-radius: 0px 0px 10px 10px;
    -webkit-border-radius:  0px 0px 10px 10px;
}

We’ve added three items. The W3C standard for adding a rounded border is border-radius but for backwards compatibility we add the –moz-border-radius for older versions of Firefox and –webkit-border-radius for older versions of Chrome.

Now fire these up in Firefox and Chrome and you will have your rounded corner.  If you are using IE however, no luck.

Firefox sample:

image

Now to make this magic happen in IE we sprinkle in just a dash of CSS3Pie.  After downloading CSS3 Pie add the .htc file to your project and then add the below line to your page element in the site.css file:

.page
{
    width: 960px;
    background-color: #fff;
    margin: 20px auto 0px auto;
    border: 1px solid #496077;
    border-radius: 0px 0px 10px 10px;
    -moz-border-radius: 0px 0px 10px 10px;
    -webkit-border-radius:  0px 0px 10px 10px;
    behavior: url('./Scripts/PIE.htc');
}

Fire up IE again and CSS3 rounded corners appear thanks to CSS3Pie.

image 

Happy Coding

Posted 09.29.2010  #    Comments [0]  |