Tuesday, April 17, 2012

PHP Contact Form

                                                                      freecontactform

Export Html to Pdf using iTextSharp(GridView)


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Pdf.aspx.cs" Inherits="Pdf" %>

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Pagetitle>
head>
<body>
<form id="form1" runat="server">
  <div>
      <asp:GridView ID="GridView1" runat="server">
      asp:GridView>
      <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Pdf" />div>
form>
body>
html>



using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
using iTextSharp.text.html;

public partial class Pdf : MyPage
{
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        GridView1.DataSource = GetData();
        GridView1.DataBind();
    }

}
protected void Button1_Click(object sender, EventArgs e)
{
    MyPage tmpPage = new MyPage();
    HtmlForm form = new HtmlForm();
    form.Controls.Add(GridView1);
    tmpPage.Controls.Add(form);
    StringWriter sw = new StringWriter();
    HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);
    form.Controls[0].RenderControl(htmlWriter);
    string htmlContent = sw.ToString();
    Document document = new Document();
    // step 2:
    // we create a writer that listens to the document
    // and directs a PDF-stream to a file
    PdfWriter.GetInstance(document, new FileStream("c:\\Chap0101.pdf", FileMode.Create));

    // step 3: we open the document
    document.Open();

    // step 4: we add a paragraph to the document
    //document.Add(new Paragraph(htmlContent.ToString()));

    System.Xml.XmlTextReader _xmlr = new System.Xml.XmlTextReader(new StringReader(htmlContent));

    HtmlParser.Parse(document, _xmlr);

    // step 5: we close the document
    document.Close();

    ShowPdf("c:\\Chap0101.pdf");

}

private void ShowPdf(string s)
{
    Response.ClearContent();
    Response.ClearHeaders();
    Response.AddHeader("Content-Disposition", "inline;filename=" + s);
    Response.ContentType = "application/pdf";
    Response.WriteFile(s);
    Response.Flush();
    Response.Clear();
}
public DataSet GetData()
{
    DataSet ds = new DataSet();
    DataTable dt = new DataTable("Product");
    DataRow dr;
    dt.Columns.Add(new DataColumn("Price", typeof(Int32)));
    dt.Columns.Add(new DataColumn("DisCount", typeof(Int32)));
    dt.Columns.Add(new DataColumn("SellPrice", typeof(Int32)));
    for (int i = 1; i <= 10; i++)
    {
        dr = dt.NewRow();
        dr[0] = i;
        dr[1] = i * 2;
        dr[2] = 1 * 3;
        dt.Rows.Add(dr);
    }
    ds.Tables.Add(dt);
    Session["dt"] = dt;
    return ds;
}
}
*Create a new clas Mypage.cs in app_code folder.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// 
/// Summary description for MyPage
/// 
public class MyPage : Page
{
 public override void VerifyRenderingInServerForm(Control control)
 {
     GridView grid = control as GridView;
     if (grid != null && grid.ID == "GridView1")
         return;
     else
         base.VerifyRenderingInServerForm(control);

 }
}



More information visit:
how-to-export-content-of-gridview-to.html

Printing GridView from ASp.net

                                                         
                                                             CODE

Wednesday, April 4, 2012

Configuring web application to utilise ASP.NET Application Services database


In  article Install ASP.NET Application Services database step by step guide is provided to install ASP.NET Application Services database regard less of SQL Server version. Installing / configuring Application services database allows multiple applications to utilise the database to implement application authentication and authorization.
After installation of services database, it is required to configure ASP.NET application to utilise the ASP.NET Services database(called as Membership database as well).
I come across multiple number of repeating postings at www.asp.net/forums with exceptions when post holders try to utilise ASP.NET application services database to authenticate or authorise end users. Common exceptions noted are ‘sql exceptions’ or ‘Invalid end user credentials when tried to use Login control’ or similar exception.
The reason behind most of these exceptions are not configuring web application to utilise SQL Server installed ASP.NET Application Services database. When responding to those repeating postings on asp.net forums i decided to write an article explaining this process instead of repeating the same info multiple times.
This article explains step by step process of configuring ASP.NET Web application to utilise SQL Server installed ASP.NET Application Services database.
  1. Copying and configuring connection String
  2. Copying and configuring Membership, Roles and Profile sections
  3. Using ASP.NET Web application Configuration tool to choose providers
Hope you find it helpful.
Step 1
Copying and configuring connection String
Note that configuration settings in Web.config file are inherited from machine.config file on your machine. In order to configure web application to utilise Application Services database it is required to copy related sections from machine.config file, which is located at
C:\windows\Microsoft.NET\Framework\v2.0.50727\CONFIG
NB:- Make sure that you are not making any changes to your machine.config file.
To Do:- Copy connection string from machine.config file as shown below.
<connectionStrings>
	<add name="LocalSqlServer" 
	connectionString="data source=.\SQLEXPRESS;
	Integrated Security=SSPI;
	AttachDBFilename=|DataDirectory|aspnetdb.mdf;
	User Instance=true" 
	providerName="System.Data.SqlClient"/>
connectionStrings>
To Do:- Paste above connection string from machine.config into Web.config and 
change required properties as shown below.
<add name="" 
connectionString="Server=;
Database=;
User ID=;
Password="
providerName="System.Data.SqlClient"/>
Step 2
Copying and configuring Membership, Roles and Profile sections
Note that depending on your application requirements you need either or combination 
or all of these three sections.
  1. Membership
  2. Roles
  3. Profile
To Do:- Copy Membership, Roles and Profile sections from machine.config intoWeb.config and configure required properties.
<membership>
	<providers>

	<add name="AspNetSqlMembershipProvider" 
        type="System.Web.Security.SqlMembershipProvider,
	System.Web, Version=2.0.0.0, Culture=neutral, 
	PublicKeyToken=b03f5f7f11d50a3a" 
	connectionStringName="LocalSqlServer" 
	enablePasswordRetrieval="false" 
	enablePasswordReset="true" 
	requiresQuestionAndAnswer="true" 
	applicationName="/" 
	requiresUniqueEmail="false" 
	passwordFormat="Hashed" 
	maxInvalidPasswordAttempts="5" 
	minRequiredPasswordLength="7" 
	minRequiredNonalphanumericCharacters="1" 
	passwordAttemptWindow="10" 
	passwordStrengthRegularExpression=""/>
	
	providers>
membership>

<profile>
	<providers>
	
	<add name="AspNetSqlProfileProvider" 
	connectionStringName="LocalSqlServer" 
	applicationName="/" 
	type="System.Web.Profile.SqlProfileProvider, 
	System.Web, Version=2.0.0.0, Culture=neutral, 		
        PublicKeyToken=b03f5f7f11d50a3a"/>
	
	providers>
profile>

<roleManager>
	<providers>

	<add name="AspNetSqlRoleProvider" 
	connectionStringName="LocalSqlServer" 
	applicationName="/" 
	type="System.Web.Security.SqlRoleProvider, 
	System.Web, Version=2.0.0.0, Culture=neutral,
	PublicKeyToken=b03f5f7f11d50a3a"/>
	
	providers>
roleManager>
To Do:- After copying above sections into Web.config, make sure you modify 
minimum required attributes such as name, connectionStringName and
ApplicationName
  • Note that depending on your application requirements you may modify other attributes mostly in Membership section.
After modifying minimum attributes in Membership, Roles and Profilesections, these sections looks similar as shown below.
<membership defaultProvider="AspNetMembershipProvider">
	<providers>
	<add connectionStringName=" 
	enablePasswordRetrieval="false" 
	enablePasswordReset="true" 
	requiresQuestionAndAnswer="true" 
	applicationName="" 
	requiresUniqueEmail="false" 
	passwordFormat="Clear" 
	maxInvalidPasswordAttempts="5" 
	minRequiredPasswordLength="7" 
	minRequiredNonalphanumericCharacters="0" 
	passwordAttemptWindow="10" 
	passwordStrengthRegularExpression="" 
	name="AspNetMembershipProvider"
        type="System.Web.Security.SqlMembershipProvider, 
	System.Web, Version=2.0.0.0, Culture=neutral,
        PublicKeyToken=b03f5f7f11d50a3a"/>
	providers>
membership>

<roleManager enabled="true" defaultProvider="AspNetRoleProvider">
	<providers>
	<add connectionStringName=" 
	applicationName="" 
	name="AspNetRoleProvider" 
	type="System.Web.Security.SqlRoleProvider, 
	System.Web, Version=2.0.0.0, Culture=neutral,
        PublicKeyToken=b03f5f7f11d50a3a"/>
	providers>
roleManager>

<profile>
	<providers>
	
	<add name="" 
	connectionStringName="" 
	applicationName="/" 
	type="System.Web.Profile.SqlProfileProvider, 
	System.Web, Version=2.0.0.0, Culture=neutral,
        PublicKeyToken=b03f5f7f11d50a3a"/>
	
	providers>
profile>
NB:- Make sure that application Name property is set at all the time as
suggested by Scott Guthrie here

Step 3
Using ASP.NET Web application Configuration tool to choose providers
After adding and modifying required sections as explained above, save your Web.config and configure your web application to utilise ASP.NET Application Services Database as explained below.
To Do:- Start ASP.NET Configuration tool from Website menu (shown below). Note that ASP.NET configuration tool can be initiated from Solution Explorer menu as well. 
ASP.NET Configuration Tool
Selecting ASP.NET Configuration opens Web Site Administration Tool in browser.
To Do:-Select Provider Configuration hyperlink as shown below.
Config_Tool
Selecting Provider Configuration navigates to Provider page where you can choose either Single provider or different provider for each feature as shown below.

  • To Do:- You can choose either of the above options available. For this tutorial choosing ‘Select a different provider each feature’ option. By doing so each providercan choose different data sources.
Selecting Select a different provider for each feature (advanced) hyperlink navigates to next page where you can select a provider for each feature as shown below.
Provider_Selection
On this screen you can see provider name(from provider section), choose a provider
for each feature i.e., Membership, Roles and Profile and select Ok.
Thats it. You are ready to fly! Configuration is done.
  • Testing:- In order to make sure your ASP.NET application services database is configured to be used by web application, you can create a new user by selectingSecurity tab with in Web Site Administration tool, then Create User hyperlink. After creating the user make sure that you see the same information in ASP.NET Application Services database aspnet_Users
References

Sunday, April 1, 2012

All World Newspapers in a single Web Page

We have lot of technologies to update news such as television, radio, computer etc,. Even peoples are showing their more interest on reading newspapers to update daily news. Since we can get full information about the news. We have lot of newspapers for daily updates. In our country India itself, we have more than 100 newspapers.


CLICK HERE

Free Video Flip and Rotate

Free Video Flip and Rotate

Requirements
Windows XP SP3, Vista, Windows 7 and .Net Framework 2 SP2
Description
Free Video Flip and Rotate. Rotate video or flip video with one mouse click.
Very fast and easy. 7 predefined presets:
- rotate video 90 CW;
- rotate video 180;
- rotate video 90 CCW;
- flip video horizontal;
- flip video vertical;
- flip video vertical and rotate 90 CW;
- flip video vertical and rotate 90 CCW.
Free Video Flip and Rotate contains no spyware or adware. It's clearly free and absolutely safe to install and run.


http://www.dvdvideosoft.com/products/dvd/Free-Video-Flip-and-Rotate.htm