1
Posted on 6:20 AM by prajeesh and filed under , ,
Printing is a common feature needed in almost every type of web pages, there is a plenty of options to include print feature in your web page, i would like to describe two methods.

1.Printing Using java script
It is a simple task

This HTML code will return a Print button and you can click this button to print your web page.

2.Printing using web controls using ASP.net

Little programming effort is needed for printing web controls in your ASP.net application.
If you want to print contents of a web control in your ASP.net page, you can use following code segment, it is also using javascript for printing but it prints selected control only.
///
/// Prints any web control Grid view, DataGrid, Page , Panel etc.
///
///

public static void PrintWebControl(Control ctrl)
{
String Script;
StringWriter stringWrite = new StringWriter ();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
if ( ctrl is WebControl )
{
Unit w = new Unit(400, UnitType.Pixel);
((WebControl)ctrl).Width = w;
}
Page pg = new Page ();
if (Script != string.Empty )
{
pg.RegisterStartupScript ("PrintJavaScript",Script);
}
HtmlForm frm = new HtmlForm ();
pg.Controls.Add (frm);
frm.Attributes.Add ("runat","server");
frm.Controls.Add (ctrl);
string scr = " ";
htmlWrite.Write(scr);
pg.DesignerInitialize();
pg.RenderControl(htmlWrite);
string strHTML = stringWrite.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.Write(" ");
HttpContext.Current.Response.End();
}
You can pass the control to be printed as a parameter of PrintWebControl(Control ctrl) function.
Happy coding Shout it kick it on DotNetKicks.com
0
Posted on 5:37 AM by prajeesh and filed under , , ,
In certain occasions you may need to export / import large excel spreadsheet to SQL server data base. In this small and simple article i would like to demonstrate the process of exporting / importing Excel Data into SQL server database.
Step 1:
I am assuming you have created a folder and uploaded your Microsoft Excel worksheet in that folder.
Step 2:
You can create class for creating an export function
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.OleDb;
///
/// Class for Exporting Excel Data to SQL server
///

public class clsExcelToSqlServer
{
public clsExcelToSqlServer()
{
//
// TODO: Add constructor logic here
//
}
private string _FilePath;
public String FilePath
{
get { return _FilePath; }
set { _FilePath = value; }
}
public DataTable getDataFromExcelSheet()
{
try
{
//File path of Excel Spread sheet
FilePath = HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath) +
"/ExcelFolder/ExcelAppliance.xls";
//Connection string to connect Excel data
string strConnectionString = string.Empty; strConnectionString =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ FilePath + @";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""";
OleDbConnection cnCSV = new OleDbConnection(strConnectionString);
cnCSV.Open();
//Selecting all rows from excel sheet
OleDbCommand cmdSelect = new OleDbCommand(@"SELECT * FROM [Sheet1$]", cnCSV);
OleDbDataAdapter daCSV = new OleDbDataAdapter();
daCSV.SelectCommand = cmdSelect;
DataTable dtCSV = new DataTable();
//Filling excel data into data table
daCSV.Fill(dtCSV);
cnCSV.Close();
daCSV = null;
return dtCSV;
}
catch (Exception ex)
{
return null;
}
finally { }
}
}
getDataFromExcelSheet() function returns a Data Table and you can use this Data table to export data into to SQL Server.
Shout it kick it on DotNetKicks.com
0
Posted on 12:23 AM by prajeesh and filed under


Kerala Microsoft user group (K-Mug) launch is on October 25th, For more details visit K-Mug Official website Shout it kick it on DotNetKicks.com
0
Posted on 8:21 AM by prajeesh and filed under
Silverlight 2 is released, you can download it from Here.
See Scot Gu's annoucement regarding silverlight relese   Follow here .
Silver light 2 comes with dozens of built in UT controls that can be used to build applications, some are  Silverlight DataGrid, RadioButton, CheckBox and DatePicker controls.
You can start learning silver light 2 Here
Shout it kick it on DotNetKicks.com
2
Posted on 8:23 AM by prajeesh and filed under , , ,

RSS feeds or "Rich Site Summery" are XML documents that used to publish freequently updated works, and RSS document or Web feed includes full summerized text and meta data RSS is also known as "Really Simple Syndication". For detailed information regarding RSS Feeds visit here http://en.wikipedia.org/wiki/RSS_(file_format.
Sample RSS File


<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="0.91">
<channel>
<title>Prajeesh's ASP.net Tech blog</title>
<link>http://www.prajeeshkk.blogspot.com</link>
<description>Web development help - By Prajeeesh </description>
<language>en-us</language>
<image>
<title>Prajeesh's Blog</title>
<url>http://www.prajeeshkk.blogspot.com/</url>
<link>http://www.prajeeshkk.blogspot.com/</link>
<width>90</width>
<height>36</height>
</image>
<item>
<title>Attack Update</title>
<link>http://www.prajeeshkk.blogspot.com/</link>
<description>
This is a test content for my test RSS document:My blog contains posts based on Web development, Web design , ASP.net development, javascript, HTML and CSS
By Prajeesh, October 22, 2008
</description>
</item>
<item>
<title>Test Post Second.ca</title>
<link>http://www.prajeeshkk.blogspot.com/</link>
<description>
This is another post content for testing RSS feeds
By Prajeesh, October 22, 2008
</description>
</item>
</channel>
</rss>

Creatting an RSS Feed using asp.net with C#
Step 1
Create a class clsRss and copy following code in the class.
using System;using System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using System.Data.SqlClient;
using System.Text;
/// <summary>/// Summary description for clsRss

///
</summary>public class clsRss

{

clsArticle ObjArticle = new clsArticle();
public clsRss()
{

//
// TODO: Add constructor logic here//
}
public void CreateRss_Recent()
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "text/xml";XmlTextWriter objX = new XmlTextWriter(HttpContext.Current.Response.OutputStream, Encoding.UTF8);objX.WriteStartDocument();
objX.WriteStartElement("rss");
objX.WriteAttributeString("version","2.0");
objX.WriteStartElement("channel");
objX.WriteElementString("title", "prajeesh's Tech blog- Recent articles ");
objX.WriteElementString("link",http://www.testsite.com/rss.aspx);
objX.WriteElementString("description","Latest articles from your site .");objX.WriteElementString("copyright","(c) 2008, Your web solutions. All rights reserved.");
objX.WriteElementString("ttl","5");//
// Suppose Article_Recent_Rss() is a function that returns data table with columns Title,Description,link & Pubdate
//
DataTableReader objReader = ObjArticle.Artilce_Recent_Rss().CreateDataReader();
while (objReader.Read()){
objX.WriteStartElement("item");
objX.WriteElementString("title",objReader["Title"].ToString());
objX.WriteElementString("description",objReader["Summery"].ToString());
objX.WriteElementString("link",objReader["articleurl"].ToString() );
objX.WriteElementString("pubDate",objReader["Postdate"].ToString() );
objX.WriteEndElement();
}objReader.Close();
objX.WriteEndElement();
objX.WriteEndElement();
objX.WriteEndDocument();
objX.Flush();
objX.Close();
HttpContext.Current.Response.End();
}
}Step 2
in the page load event of feeds page, write the following code.
public partial class rss : System.Web.UI.Page
{
clsRss ObjRss = new clsRss();
protected void Page_Load(object sender, EventArgs e){
ObjRss.CreateRss_Recent(); }} Shout it kick it on DotNetKicks.com