Thursday, March 18, 2010

Align Image Center in Page Header of RDLC file

Align Image Center
There is no automatic centering behavior for the Image control, you can simulate this by writing an expression for PaddingLeft.
Follow steps:
Step 01 :
Set Location property of the Image control to (0in, 0in).
Step 02:
Stretch the Image Control to full width of page header.
Step 03:
Set the Sizing property of the Image control to Clip
Step 04:
Create a new Parameter in Report say "ImageWidth" of datatype String.
Step 05:
Set Image Control Padding Left property to "=Parameters!ImageWidth.Value"
Step 06:
Now calculate value to set Left-Padding for Image Control,

//Calculate Left Padding for Image Control based on Image Size, passed as memory stream.

private string CalculateLeftPadding(byte[] imageData)
{
int DPI = 96; // DPI is typically 96

// Get Width of Image
int ImageWidthInPixels = System.Drawing.Image.FromStream(new System.IO.MemoryStream(imageData)).Width;

// Page Width of your RDLC file
double pageWidthInInches = 7; // By default i have set value to 7

//calculate the half of the difference between the width of the image and the width of the column.
double padding = (pageWidthInInches - ImageWidthInPixels / DPI) / 2;

// The padding property of Image Control takes a size, which is a string including the size and the units.
return Convert.ToString(Math.Round(padding, 2)) + "in";
}


Step 07:
Now just pass this value to your RDLC File --

string LeftPaddingForLogo = CalculateLeftPadding(imageData);
ReportParameter p1 = new ReportParameter("ImageWidth", LeftPaddingForLogo);
reportViewer.LocalReport.SetParameters(new ReportParameter[] { p1});

Set up IIS SMTP Service to Send Email

To install IIS SMTP
    Windows 2003
      1. Under Add/Remove Programs, choose to Add/Remove a Windows Component.
      2. Choose IIS and SMTP, and install. You may need access to your operating system's install CD.
      3. Reboot after installation.
    Windows 2008
      1. Select Start|Control Panel.
      2. Double click Programs and Features.
      3. Click Turn Windows Features on and off. This starts the Server Manager.
      4. Click Add Features.
      5. Check SMTP Server. Click Install.

To setup IIS SMTP

    Windows 2003
      1. Check whether the SMTP service is running. Right click on My Computer and select Manage.
      2. In Computer Management expand Services and Applications.
      3. Expand Internet Information Services and right click on Default SMTP Virtual Server and select Properties.
      4. Select the Delivery tab and press the Advanced button.
      5. In the Smart Host enter the IP Address of your mail server and the Fully qualified domain name of the server listed in the Smart Host for the Fully-qualified domain name.
      6. In the Masquerade domain enter the domain name of your primary email domain (e.g. gmail.com).
      7. Press OK to accept the changes.
    Windows 2008
      1. Click Start|Administrative Tools|Internet Information Services (IIS) 6.0 Manager.
      3. Expand and right click on SMTP Virtual Server and select Properties.
      4. Select the Delivery tab and press the Advanced button.
      5. In the Smart Host textbox enter the IP Address of your mail server and the Fully qualified domain name of the server listed in the Smart Host for the Fully-qualified domain name.
      6. In the Masquerade domain enter the domain name of your primary email domain (e.g. gmail.com).
      7. Press OK to accept the changes.

Sunday, March 7, 2010

Register ASP.NET Web User Controls in Web.config

We can register user control to Web.config file with the following entry:
Web config entry would look like:
<configuration>

<system.web>
<
pages>
<controls>

<
add tagPrefix="MyControl" src="~/Controls/WebUserControl.ascx" tagName="MyBtn/>
controls>
pages>

system.web>
configuration>

Once the web config entry is made. The control can then be used in any page like this:

<body>

<form id="form1" runat="server">
<MyControl:MyBtn ID="MyUserControl" runat="server" />
form>
body>

Thursday, March 4, 2010

How to scope Theme in ASP.net

How to scope Theme ?

Themes are a way to define properties of pages and controls, and can be used to provide consistent look across pages. There are several different levels of applying a theme to an individual control, a page, or an application.

  1. Control Level
    Define a named skin (an entry in a .skin file having the SkinID property set) and then apply it to an individual control
    SkinID="BlueButton" />
  2. Page Level
    A defined theme can be applied to an individual page by specifying the Theme or StyleSheetTheme attribute of the @Page directive of the page
    <%@ Page Theme="MyTheme" %>
  3. Application Level
    To define the theme for the whole application, set the theme attribute of the pages element in the web.config file of the application


    <pages theme="MyTheme" />


  4. Global Level
    Theme can also be applied globally to all the web sites on the same server. Global themes are defined the same way as Page themes, except that they’re defined in aTheme folder that is global to the server. Then you set the theme attribute of the pages element in the machine.config file.

Do you wonder if there is any difference between setting the Theme and StyleSheetTheme attribute of a @Page directive? Yes, there is. The difference is the precedence of the themes specified by the attribute. If you use the Theme attribute, the local settings will be overwritten by the Theme settings. If you use the StyleSheetTheme attribute, the local settings will be applied, regardless of what being defined in the Theme folder.

Also, a point that is worth mentioning is the designer of Visual Studio doesn’t support the Theme attribute. If you want to use the designer when developing your page, you might consider using the StyleSheetTheme attribute, then switch to using the Theme attribute for deployment.

Thanks.