Monday, December 01, 2008

To Use VS 2005 Web Deployment Projects
1.       install VS 2005 Web Deployment Project add-in at "setup" link below
 
2.       In File Name Box - "*.*" -> Click Open Button
3.       Select an available .wdproj file
Other links:
 

Saturday, November 08, 2008

Get email addressees of all users from all mails in Outlook Folder

Original Article:

http://msmvps.com/blogs/omar/archive/2006/08/09/get-email-address-of-all-users-from-all-mails-in-outlook-folder.aspx

Sometimes you want to send some important notice to everyone who has ever mailed you. Let's say you have a folder named "Friends" in Outlook where you store all the emails from your friends. Now you want to get all of their email addresses (from the folder, not from the email bodies). Pretty difficult work if you have thousands of such mails. Here's an easy way.

  • Select the folder in Outlook and press ALT+F11. It will open Visual Basic Editor.
  • Double click on ThisOutlookSession from the Project tree.
  • Set a reference to Microsoft Scripting Dictionary

  • Paste the following function:

 Hit F5 and it will run for a while. Then press Ctrl+G. You will see the email addresses in the "Immediate Window".    

Copy the whole string and you have all the email addresses from all the emails in the selected Outlook folder. There will be no duplicate address in the list.

Sub GetALLEmailAddresses()

Dim objFolder As MAPIFolder
Dim strEmail As String
Dim strEmails As String
''' Requires reference to Microsoft Scripting Runtime
Dim dic As New Dictionary
Dim objItem As Object

''Set objFolder = Application.ActiveExplorer.Selection
Set objFolder = Application.GetNamespace("Mapi").PickFolder

For Each objItem In objFolder.Items
   
   If objItem.Class = olMail Then
   
       strEmail = objItem.SenderEmailAddress

       If Not dic.Exists(strEmail) Then

           strEmails = strEmails + strEmail + vbCrLf

           dic.Add strEmail, ""

       End If

   End If
   
Next

Debug.Print strEmails

End Sub

 

Thursday, October 23, 2008

simulate: “file Streams into Memory, then JOIN the data in Memory, via LINQ to Objects”
 
I wrote up a quick little WinForms project in VS2008 with .NET Framework 3.5,
 
 
 
 
 
Code overview: 
 
1.    On Form_Load,
a.    create a List of People into DataDridView and in Memory
b.    create a List of Jobs into DataDridView and in Memory
c.    create a List of JobIds into ComboBox
2.    On ComboBox_SelectedIndexChanged,
a.    Perform LINQ to Objects query: “Select from People JOINED to Jobs by JobId”
b.    Show query result in list box
 
You can probably do this with nHibernate too.
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace FascetLINQtoObjects
{
    publicpartialclassForm1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        //-----------------------------------------------------
        //Form Scope (To hold & share LINQ Objects' state) -
        //-----------------------------------------------------
        List<Person> people = newList<Person>();
        List<Job> jobs = newList<Job>();
        bool _loaded = false;
       
        privatevoid Form1_Load(object sender, EventArgs e)
        {
            //-----------------------------------------------------
            //Form Load Load LINQ Objects' state
            //Simulate Fascet Client data streaming into Fascet Winform
            //-----------------------------------------------------
            people.Add(newPerson("Gerald", DateTime.Parse("1/2/2003"), 3));
            people.Add(newPerson("Linda", DateTime.Parse("2/2/2002"), 1));
            people.Add(newPerson("Sarah", DateTime.Parse("4/2/2002"), 1));
            people.Add(newPerson("Bill", DateTime.Parse("4/5/2006"), 2));
 
 
            jobs.Add(newJob(1, "Developer", "Microsoft", "West"));
            jobs.Add(newJob(2, "Developer", "Microsoft", "East"));
            jobs.Add(newJob(3, "Technical Account Representative", "Microsoft", "Central"));
           
            //-----------------------------------------------------
            //Bind to Jobs DataGridView
            //-----------------------------------------------------
            dgPeople.DataSource = people;
            this.dgJobs.DataSource = jobs;
 
            //-----------------------------------------------------
            //Bind to Jobs comboBox
            //-----------------------------------------------------
            this.cboJob.DataSource = jobs;
            this.cboJob.ValueMember = "ID";
            this.cboJob.DisplayMember = "ID";
 
            //-----------------------------------------------------
            //ShowPersonJob
            //-----------------------------------------------------
            int jobId = int.Parse(cboJob.SelectedValue.ToString());
            ShowPersonJob(jobId);
 
            _loaded = true;
 
        }
        privatevoid ShowPersonJob(int jobId)
        {
            //-----------------------------------------------------
            //query joined LINQ objects
            //-----------------------------------------------------
            var result = from p in people
                         from j in jobs
                         where p.JobID == j.ID
                         && j.ID == jobId
                         selectnew
                         {
                             p.Name,
                             j.Company,
                             j.Title
                         };
 
            //-----------------------------------------------------
            //display query result
            //-----------------------------------------------------
            this.listBox1.DataSource = result.ToList();
        }
 
        privatevoid cboJob_SelectedIndexChanged(object sender, EventArgs e)
        {
            //-----------------------------------------------------
            //ShowPersonJob
            //-----------------------------------------------------
            if (_loaded)
            {
                //-----------------------------------------------------
                //
                //-----------------------------------------------------
                int jobId = int.Parse(cboJob.SelectedValue.ToString());
                ShowPersonJob(jobId);
            }
        }
   
    }
}
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace FascetLINQtoObjects
{
    classPerson
    {
        string _name = "";
        publicstring Name
        {
            get { return _name; }
            set { _name = value; }
        }
        DateTime? _Birthday;
        publicDateTime? Birthday
        {
            get { return _Birthday; }
            set { _Birthday = value; }
        }
        int _jobID = 0;
        publicint JobID
        {
            get { return _jobID; }
            set { _jobID = value; }
        }
        public Person(string name, DateTime birthday, int jobID)
        {
            this._name = name;
            this._Birthday = birthday;
            this._jobID = jobID;
 
        }
    }
}
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace FascetLINQtoObjects
{
    classJob
    {
        string _title = "";
        publicstring Title
        {
            get { return _title; }
            set { _title = value; }
        }
 
        string _company = "";
        publicstring Company
        {
            get { return _company; }
            set { _company = value; }
        }
 
        int _id = 0;
        publicint ID
        {
            get { return _id; }
            set { _id = value; }
        }
 
        string _location = "";
        publicstring Location
        {
            get { return _location; }
            set { _location = value; }
        }
        public Job(int id, string title, string company, string location)
        {
            _title = title;
            _id = id;
            _company = company;
            _location = location;
        }
    }
}
 
 
 

List All Primary Keys and Foreign Keys

Original article:  http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=41896

set nocount on
create table #PK(constraint_schema sysname not null, constraint_name sysname not null, sql varchar(4000) not null, constraint PK_#PK primary key clustered(constraint_schema, constraint_name))
create table #cols(constraint_schema sysname not null, constraint_name sysname not null, column_name sysname not null, ordinal_position int not null, constraint PK_#PKcol primary key clustered(constraint_schema, constraint_name, ordinal_position))
create table #FK(constraint_schema sysname not null, constraint_name sysname not null,
unique_constraint_schema sysname not null, unique_constraint_name sysname not null,
sql varchar(4000) not null, constraint PK_#FK primary key clustered(constraint_schema, constraint_name))

insert into #PK
select constraint_schema, constraint_name, 'ALTER TABLE ' + quotename(table_schema) + '.' + quotename(TABLE_NAME) +
' ADD CONSTRAINT ' + quotename(CONSTRAINT_NAME) +
' PRIMARY KEY ' + CASE WHEN si.indid<>1 THEN 'NON' ELSE '' END +
'CLUSTERED (>cols<) WITH FILLFACTOR=' + cast(si.OrigFillFactor as varchar) + ' ON ' + quotename(fg.groupname)
AS SQL
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC
INNER JOIN sysindexes si on TC.CONSTRAINT_NAME=si.name
inner join sysfilegroups fg on si.groupid=fg.groupid
WHERE CONSTRAINT_TYPE IN('PRIMARY KEY','UNIQUE')

insert into #fk
select c.constraint_schema, c.constraint_name, c.unique_constraint_schema, c.unique_constraint_name,
'ALTER TABLE ' + quotename(F.table_schema) + '.' + quotename(F.table_name) +
' ADD CONSTRAINT ' + quotename(F.constraint_name) +
' FOREIGN KEY(>cols<) REFERENCES ' + quotename(r.table_schema) + '.' + quotename(r.table_name) +
'(>rcols<)'
AS sql
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS F
INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C ON F.constraint_schema=C.constraint_schema AND f.constraint_name=c.constraint_name AND F.constraint_type='FOREIGN KEY'
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS R ON R.constraint_schema=C.unique_constraint_schema AND r.constraint_name=c.unique_constraint_name AND r.constraint_type in ('PRIMARY KEY','UNIQUE')
ORDER BY F.table_name, r.table_name

insert into #cols
select constraint_schema, constraint_name, COLUMN_NAME, ORDINAL_POSITION from INFORMATION_SCHEMA.KEY_COLUMN_USAGE

declare @ctr int, @max int, @delim varchar(1)
select @ctr=1, @max=max(ordinal_position), @delim='' from #cols

set nocount on
while @ctr<=@max
BEGIN

update P SET SQL=Replace(SQL, '>cols<', @delim + quotename(c.column_name) + '>cols<')
FROM #PK P INNER JOIN #cols C ON P.constraint_schema=C.constraint_schema AND P.constraint_name=C.constraint_name
WHERE C.ORDINAL_POSITION=@ctr

UPDATE F SET SQL=Replace(Replace(SQL, '>cols<', @delim + quotename(c.column_name) + '>cols<'), '>rcols<', @delim + quotename(r.column_name) + '>rcols<')
FROM #FK F INNER JOIN #cols C ON F.constraint_schema=C.constraint_schema AND F.constraint_name=C.constraint_name AND C.ordinal_position=@ctr
INNER JOIN #cols R ON F.unique_constraint_schema=R.constraint_schema AND F.unique_constraint_name=R.constraint_name AND C.ordinal_position=R.ordinal_position

select @ctr=@ctr+1, @delim=','
END
set nocount on

update #PK SET SQL=Replace(SQL, '>cols<', '')
update #FK SET SQL=Replace(Replace(SQL, '>cols<', ''), '>rcols<', '')

select sql from #PK order by sql
select sql from #FK order by sql

drop table #pk
drop table #fk
drop table #cols

 

Wednesday, September 24, 2008

Here is an example of Asp.NET Web page - "complete" zip code text box

1) regex for xxx -> ="^(\d{5}|\d{5}\-\d{4})"   

2) zip code text box with

   a) regex  RegularExpressionValidator   

   b) RequiredFieldValidator               

<asp:TextBox ID="txtZip" runat="server" MaxLength="10"  Width="100px" ></asp:TextBox>

                            <asp:RegularExpressionValidator

                                ID="RequiredFieldValidatorZip"

                              ControlToValidate="txtZip"

                              ValidationExpression="^(\d{5}|\d{5}\-\d{4})$"

                              ErrorMessage="Zip code must be numeric nnnnn or nnnnn-nnnn."

                              Display="dynamic"

                              RunAt="server"></asp:RegularExpressionValidator>

                               <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Zip is a required field!" ControlToValidate="txtZip"></asp:RequiredFieldValidator>

 

Thursday, August 28, 2008

 

Windows XP Backup

http://www.microsoft.com/windowsxp/using/setup/learnmore/bott_03july14.mspx

Wednesday, August 13, 2008

Generic  xmlTextReader
 
Original article:
 
 
                    ////------------------------------------------------------------------
                    ////convert XML string to MemoryStream
                    ////------------------------------------------------------------------
                    MemoryStream memoryStream = new MemoryStream();
                    byte[] data = Encoding.Unicode.GetBytes(strippedXml);
                    memoryStream.Write(data, 0, data.Length);
                    memoryStream.Position = 0;
 
                    ////------------------------------------------------------------------
                    ////convert MemoryStream to xmlTextReader
                    ////------------------------------------------------------------------
                    //XmlTextReader xmlTextReader = new XmlTextReader(Server.MapPath("test.xml"));
                    XmlTextReader xmlTextReader = new XmlTextReader(memoryStream);
 
                    ////------------------------------------------------------------------
                    ////
                    ////------------------------------------------------------------------
                    while (xmlTextReader.Read())
                    {
                        switch (xmlTextReader.NodeType)
                        {
                            case XmlNodeType.Element:
                                Debug.WriteLine(xmlTextReader.Name.ToString());
                                break;
                            case XmlNodeType.Text:
                                Debug.WriteLine(xmlTextReader.Value.ToString());
                                break;
                            case XmlNodeType.EndElement:
                                Debug.WriteLine(xmlTextReader.Name.ToString());
                                break;
                        }
                    }

Monday, August 11, 2008

Original Article:

http://bytes.com/forum/thread176986.html

Is there a simple way to indent xml with dotnet? SQL Server returns a long xml string that is hard
> to read.[/color]

XmlReader r = new XmlTextReader(new StringReader(myXML));
StringWriter sw = new StringWriter();
XmlTextWriter w = new XmlTextWriter(sw);
w.Formatting = Formatting.Indented;
while (r.Read())
w.WriteNode(r, false);
w.Close();
r.Close();
Console.WriteLine(sw.ToString());
--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Thursday, July 31, 2008

 

Users Guide

http://cvsgui.sourceforge.net/winhtml/wincvs11.htm

 

 

Users Guide

http://cvsgui.sourceforge.net/winhtml/wincvs11.htm

Monday, July 28, 2008

1) http://blogs.msdn.com/visio/archive/2006/06/13/624391.aspx

1a) http://office.microsoft.com/en-us/visio/HA011822551033.aspx

2) http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.visio.developer&tid=bc85a37f-451c-46c1-b18b-5201dc10ec9a&cat=en_US_7dd7f818-5a21-4dac-938b-9ac892ab60f3&lang=en&cr=US&sloc=&p=1

Hi,
I am trying to programatically automate the Org Chart Wizard(Visio 2003) in
C#. But when I attempt to connect to a SQL Server 2005, I get an error
message- "Invalid data. Your data file is empty".
I tried programming Excel file to be the data source, it worked fine.
I manually ran the wizard using the SQL data source, it worked fine.
But when I try to code it to work with the same SQL Server data source, I
get this error. It is able to connect to the data source but it is not able
to connect to the database.
I tried changing the name of the datasource, changing it to a different
server, tried connecting it to different databases but it does not work for
any database.

The code for connecting to database is-

commandPart = "/DATASOURCE="
+ formatHelper.StringToFormulaForString(data_source_name);
commandPart = commandPart + "," + "/TABLE=";
commandPart = commandPart +
formatHelper.StringToFormulaForString(Table_containing_information);
commandPart = commandPart + "," + "/DBQUALIFIER=";
commandPart = commandPart +
formatHelper.StringToFormulaForString(database_name);
chartWizard.Run(command + commandPart);


I tried running the orgwiz.exe with command line arguements, but again it
can connect to the data source but it says "Invalid data. Your data file is
empty"
Please help.
Thanks,
Archana

 

 

 

1) nHibernate Quick Start Guide

http://www.hibernate.org/362.html

 1a) NHibernate Best Practices with ASP.NET, 1.2nd Ed

http://www.codeproject.com/KB/architecture/NHibernateBestPractices.aspx

2) http://www.beansoftware.com/asp.net-tutorials/nhibernate-log4net.aspx

Tuesday, April 29, 2008

find columns and tables in a view

 

SELECT  vObj.name AS vName, vObj.id AS vID, vObj.xtype AS vType,

          dep.depid, dep.depnumber, tObj.name AS tName, col.colid,

          col.name AS cName

FROM         sysobjects vObj LEFT OUTER JOIN

             sysdepends dep ON vObj.id = dep.id LEFT OUTER JOIN

             sysobjects tObj ON dep.depid = tObj.id LEFT OUTER JOIN

             syscolumns col ON dep.depnumber = col.colid

                   AND tObj.id = col.id

WHERE   vObj.xtype = 'V' And vObj.category = 0

and   vObj.name = 'vw1_inv_item_det'

ORDER BY vObj.name, tObj.name, col.name

 

Saturday, April 26, 2008

original article:

http://sqlserver2000.databases.aspfaq.com/can-i-make-sql-server-format-dates-and-times-for-me.html

 

Many people have asked if there is a way to make SQL Server behave the way FORMAT works in VB (and FormatDateTime in VBScript). What they'd like to see is the ability to tell SQL Server to format a date with long date and time, or in MM/DD/YYYY format, instead of having to memorize existing format conversion numbers and/or manipulate the strings themselves. For example, to get today's date in YYYYMMDD format, you currently need to call the following: 
 
SELECT CONVERT(CHAR(8), GETDATE(), 112)
 
What does the 112 mean? Nothing. It's just an arbitrary number representing this specific format (Kalen Delaney's Inside SQL Server 2000 has a detailed explanation of the more commonly-used conversions). 
 
Now, wouldn't it be nice to be able to say this: 
 
SELECT CONVERT(VARCHAR, GETDATE(), 'YYYYMMDD')
 

 
Well, now you can, if you're using SQL Server 2000. I designed this scalar user-defined function for specifically this purpose. 
 
CREATE FUNCTION dbo.FormatDateTime 

    @dt DATETIME, 
    @format VARCHAR(16) 

RETURNS VARCHAR(64) 
AS 
BEGIN 
    DECLARE @dtVC VARCHAR(64) 
    SELECT @dtVC = CASE @format 
 
    WHEN 'LONGDATE' THEN 
 
        DATENAME(dw, @dt) 
        + ',' + SPACE(1) + DATENAME(m, @dt) 
        + SPACE(1) + CAST(DAY(@dt) AS VARCHAR(2)) 
        + ',' + SPACE(1) + CAST(YEAR(@dt) AS CHAR(4)) 
 
    WHEN 'LONGDATEANDTIME' THEN 
 
        DATENAME(dw, @dt) 
        + ',' + SPACE(1) + DATENAME(m, @dt) 
        + SPACE(1) + CAST(DAY(@dt) AS VARCHAR(2)) 
        + ',' + SPACE(1) + CAST(YEAR(@dt) AS CHAR(4)) 
        + SPACE(1) + RIGHT(CONVERT(CHAR(20), 
        @dt - CONVERT(DATETIME, CONVERT(CHAR(8), 
        @dt, 112)), 22), 11) 
 
    WHEN 'SHORTDATE' THEN 
 
        LEFT(CONVERT(CHAR(19), @dt, 0), 11) 
 
    WHEN 'SHORTDATEANDTIME' THEN 
 
        REPLACE(REPLACE(CONVERT(CHAR(19), @dt, 0), 
            'AM', ' AM'), 'PM', ' PM') 
 
    WHEN 'UNIXTIMESTAMP' THEN 
 
        CAST(DATEDIFF(SECOND, '19700101', @dt) 
        AS VARCHAR(64)) 
 
    WHEN 'YYYYMMDD' THEN 
 
        CONVERT(CHAR(8), @dt, 112) 
 
    WHEN 'YYYY-MM-DD' THEN 
 
        CONVERT(CHAR(10), @dt, 23) 
 
    WHEN 'YYMMDD' THEN 
 
        CONVERT(VARCHAR(8), @dt, 12) 
 
    WHEN 'YY-MM-DD' THEN 
 
        STUFF(STUFF(CONVERT(VARCHAR(8), @dt, 12), 
        5, 0, '-'), 3, 0, '-') 
 
    WHEN 'MMDDYY' THEN 
 
        REPLACE(CONVERT(CHAR(8), @dt, 10), '-', SPACE(0)) 
 
    WHEN 'MM-DD-YY' THEN 
 
        CONVERT(CHAR(8), @dt, 10) 
 
    WHEN 'MM/DD/YY' THEN 
 
        CONVERT(CHAR(8), @dt, 1) 
 
    WHEN 'MM/DD/YYYY' THEN 
 
        CONVERT(CHAR(10), @dt, 101) 
 
    WHEN 'DDMMYY' THEN 
 
        REPLACE(CONVERT(CHAR(8), @dt, 3), '/', SPACE(0)) 
 
    WHEN 'DD-MM-YY' THEN 
 
        REPLACE(CONVERT(CHAR(8), @dt, 3), '/', '-') 
 
    WHEN 'DD/MM/YY' THEN 
 
        CONVERT(CHAR(8), @dt, 3) 
 
    WHEN 'DD/MM/YYYY' THEN 
 
        CONVERT(CHAR(10), @dt, 103) 
 
    WHEN 'HH:MM:SS 24' THEN 
 
        CONVERT(CHAR(8), @dt, 8) 
 
    WHEN 'HH:MM 24' THEN 
 
        LEFT(CONVERT(VARCHAR(8), @dt, 8), 5) 
 
    WHEN 'HH:MM:SS 12' THEN 
 
        LTRIM(RIGHT(CONVERT(VARCHAR(20), @dt, 22), 11)) 
 
    WHEN 'HH:MM 12' THEN 
 
        LTRIM(SUBSTRING(CONVERT( 
        VARCHAR(20), @dt, 22), 10, 5) 
        + RIGHT(CONVERT(VARCHAR(20), @dt, 22), 3)) 
 
    ELSE 
 
        'Invalid format specified' 
 
    END 
    RETURN @dtVC 
END 
GO
 
(If you're using SQL Server 7.0, you can't create UDFs; so, I suppose you could put this logic into a stored procedure, and put the result into an output parameter.) 
 
Sample usage: 
 
DECLARE @now DATETIME 
SET @now = GETDATE() 
 
PRINT dbo.FormatDateTime(@now, 'LONGDATE') 
PRINT dbo.FormatDateTime(@now, 'LONGDATEANDTIME') 
PRINT dbo.FormatDateTime(@now, 'SHORTDATE') 
PRINT dbo.FormatDateTime(@now, 'SHORTDATEANDTIME') 
PRINT dbo.FormatDateTime(@now, 'UNIXTIMESTAMP') 
PRINT dbo.FormatDateTime(@now, 'YYYYMMDD') 
PRINT dbo.FormatDateTime(@now, 'YYYY-MM-DD') 
PRINT dbo.FormatDateTime(@now, 'YYMMDD') 
PRINT dbo.FormatDateTime(@now, 'YY-MM-DD') 
PRINT dbo.FormatDateTime(@now, 'MMDDYY') 
PRINT dbo.FormatDateTime(@now, 'MM-DD-YY') 
PRINT dbo.FormatDateTime(@now, 'MM/DD/YY') 
PRINT dbo.FormatDateTime(@now, 'MM/DD/YYYY') 
PRINT dbo.FormatDateTime(@now, 'DDMMYY') 
PRINT dbo.FormatDateTime(@now, 'DD-MM-YY') 
PRINT dbo.FormatDateTime(@now, 'DD/MM/YY') 
PRINT dbo.FormatDateTime(@now, 'DD/MM/YYYY') 
PRINT dbo.FormatDateTime(@now, 'HH:MM:SS 24') 
PRINT dbo.FormatDateTime(@now, 'HH:MM 24') 
PRINT dbo.FormatDateTime(@now, 'HH:MM:SS 12') 
PRINT dbo.FormatDateTime(@now, 'HH:MM 12') 
PRINT dbo.FormatDateTime(@now, 'goofy')

Sunday, April 20, 2008

C# Excel Export from ASP.NET Page

 

-----------------

--web Page - ExcelExport.aspx

-----------------

 

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="ExcelExport.aspx.cs" Inherits="Forms_Techniques_ExcelExport" Title="Untitled Page" %>

 

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:GridView ID="GridView1" runat="server">

    </asp:GridView>

    <br />

   <asp:LinkButton ID="LinkButton1" runat="server"

       

        onclientclick="window.open('ExcelExport.aspx?showExcel=true', 'Show_Excel','width=700,height=500,resizable=1,status=1,toolbar=1,menubar=1,scrollbars=1,location=0');"

        Font-Size="Small">Export Data to Excel</asp:LinkButton>

    </asp:Content>

 

-----------------

--Code Behind

-----------------

using System;

using System.Collections;

using System.Configuration;

using System.Data;

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.Linq;

 

public partial class Forms_Techniques_ExcelExport : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        dsContacts ds = new dsContacts();

        dsContacts.ContactDataTable dt = ds.Contact;

        //dsContactsTableAdapters.ContactTableAdapter ta = new dsContactsTableAdapters.ContactTableAdapter();