<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Mecit Atmaca</title><subtitle type="html">Thoughts on Software &amp; Process Engineering</subtitle><id>http://weblogs.asp.net/mecitatmaca/atom.aspx</id><link rel="alternate" type="text/html" href="http://weblogs.asp.net/mecitatmaca/default.aspx" /><link rel="self" type="application/atom+xml" href="http://weblogs.asp.net/mecitatmaca/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.20510.895">Community Server</generator><updated>2008-10-22T21:21:49Z</updated><entry><title>Server-side Office Integration -7 (Conclusion)</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/mecitatmaca/archive/2008/11/03/server-side-office-integration-7-conclusion.aspx" /><id>http://weblogs.asp.net/mecitatmaca/archive/2008/11/03/server-side-office-integration-7-conclusion.aspx</id><published>2008-11-04T04:28:00Z</published><updated>2008-11-04T04:28:00Z</updated><content type="html">&lt;P&gt;Voow, I am almost done. On this Sunday night, at Panera, I have enjoyed writing while listening to the jazz and drinking coups of tea (3, so far). &lt;/P&gt;
&lt;P&gt;Alright, let's summarize briefly what we have done so far in these series: After giving some intro, In this complete but simple web application, we import data from an excel spreadsheet uploaded by the user into a database table by leveraging .NET 3.5 framework and ExcelPackage with C#. &lt;/P&gt;
&lt;P&gt;Plus, we expose to some other areas of application development: &lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Best practices and Enterprise Library (used Data and Logging Blocks). Later on, I will deep into more details hopefully &lt;/LI&gt;
&lt;LI&gt;Object serialization and de-serializaition &lt;/LI&gt;
&lt;LI&gt;File operations using System.IO namespace (FileInfo, Stream/FileStream) &lt;/LI&gt;
&lt;LI&gt;Resource releases/disposal once it is done by using 'using' blocks &lt;/LI&gt;
&lt;LI&gt;XML Document &lt;/LI&gt;
&lt;LI&gt;Use of XPATH for accessing XML content. &lt;/LI&gt;
&lt;LI&gt;Use XML Document as way of importing data (like a Batch process) &lt;/LI&gt;
&lt;LI&gt;T-SQL Script for reading data from an XML Document &lt;/LI&gt;
&lt;LI&gt;Rendering data as an Office document &lt;/LI&gt;
&lt;LI&gt;Use of Data Controls. &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;I will also publish the solution. Please note that this is just a sample application, I have used very simple development architecture (UI and Business), it is not optimized nor tested well.&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;I think I am done. Bye for now &amp;amp; All the Best!. &lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=scid:0767317B-992E-4b12-91E0-4F059A8CECA8:041b0360-6240-49c5-9a45-10dc7b8a7b70 style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;Technorati Tags: &lt;A href="http://technorati.com/tags/Best%20Practices%20&amp;amp;%20Design" rel=tag mce_href="http://technorati.com/tags/Best%20Practices%20&amp;amp;%20Design"&gt;Best Practices &amp;amp; Design&lt;/A&gt;,&lt;A href="http://technorati.com/tags/Office%20Integration" rel=tag mce_href="http://technorati.com/tags/Office%20Integration"&gt;Office Integration&lt;/A&gt;,&lt;A href="http://technorati.com/tags/How%20to%20import%20excel%20spreadsheet%20into%20a%20database%20table" rel=tag mce_href="http://technorati.com/tags/How%20to%20import%20excel%20spreadsheet%20into%20a%20database%20table"&gt;How to import excel spreadsheet into a database table&lt;/A&gt;,&lt;A href="http://technorati.com/tags/Data%20Application%20Block" rel=tag mce_href="http://technorati.com/tags/Data%20Application%20Block"&gt;Data Application Block&lt;/A&gt;,&lt;A href="http://technorati.com/tags/Validation%20Block" rel=tag mce_href="http://technorati.com/tags/Validation%20Block"&gt;Validation Block&lt;/A&gt;,&lt;A href="http://technorati.com/tags/System.IO.Packaging." rel=tag mce_href="http://technorati.com/tags/System.IO.Packaging."&gt;System.IO.Packaging.&lt;/A&gt;&lt;/DIV&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6719020" width="1" height="1"&gt;</content><author><name>atmacam</name><uri>http://weblogs.asp.net/members/atmacam.aspx</uri></author><category term="C#" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/C_2300_/default.aspx" /><category term="Design Patterns" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/Design+Patterns/default.aspx" /><category term="SOA" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/SOA/default.aspx" /><category term="AJAX" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/AJAX/default.aspx" /><category term="WCF" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/WCF/default.aspx" /><category term="LINQ" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/LINQ/default.aspx" /><category term="Agile" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/Agile/default.aspx" /><category term="CLR" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/CLR/default.aspx" /><category term="Biztalk" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/Biztalk/default.aspx" /><category term="SQL Server" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/SQL+Server/default.aspx" /></entry><entry><title>First post</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/mecitatmaca/archive/2008/11/03/my-first-post.aspx" /><id>http://weblogs.asp.net/mecitatmaca/archive/2008/11/03/my-first-post.aspx</id><published>2008-11-04T03:57:03Z</published><updated>2008-11-04T03:57:03Z</updated><content type="html">&lt;p&gt;Hello everyone, &lt;/p&gt;  &lt;p&gt;This is my &lt;strong&gt;'Hello World'&lt;/strong&gt; to the Blog world. Here is my short introduction: Almost a decade of experience on mainly web-based, distributed, object oriented applications (front and back end) using .NET Framework, C#, ASP.NET, UML, Java, and XML with BizTalk, Oracle and SQL Server databases with roles of an architect, a lead developer, or a developer/programmer. Exposed to different platforms &lt;strong&gt;(.NET, J2EE)&lt;/strong&gt;, but dive into&lt;strong&gt; ASP.NET applications&lt;/strong&gt; more lately.&amp;#160; &lt;/p&gt;  &lt;p&gt;Life itself is a learning &lt;strong&gt;experience&lt;/strong&gt;, so be &lt;strong&gt;IT. &lt;/strong&gt;And here I am, I think it is time to share my experiences/thoughts with the world and to be more active within the community.&lt;/p&gt;  &lt;p&gt;Thanks to &lt;a href="http://www.misfitgeek.com/"&gt;Joe Stagner&lt;/a&gt;, and &lt;a href="http://www.jeffblankenburg.com/default.aspx"&gt;Jeffrey Blankenburg&lt;/a&gt; for setting up this blog for me.&lt;/p&gt;  &lt;p&gt;Wish you well. &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:7e44a3bb-ea88-467f-ac99-10c49c7b09a4" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Hello" rel="tag"&gt;Hello&lt;/a&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6589640" width="1" height="1"&gt;</content><author><name>atmacam</name><uri>http://weblogs.asp.net/members/atmacam.aspx</uri></author></entry><entry><title>Server-side Office Integration -6: Rendering Excel Data on cross browsers</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/mecitatmaca/archive/2008/11/02/server-side-office-integration-6-rendering-excel-data-on-cross-browsers.aspx" /><id>http://weblogs.asp.net/mecitatmaca/archive/2008/11/02/server-side-office-integration-6-rendering-excel-data-on-cross-browsers.aspx</id><published>2008-11-03T03:53:39Z</published><updated>2008-11-03T03:53:39Z</updated><content type="html">&lt;p&gt;&lt;font face="Verdana" size="2"&gt;In order to display data generated in prior calls as an Excel file on the user browser, we need to set 2 properties of the Response object (in its simplest form):&lt;/font&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;font face="Verdana" size="2"&gt;ContentType to 'application/vnd.ms-excel'&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font face="Verdana" size="2"&gt;EnableViewState to 'False'&lt;/font&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;font face="Verdana" size="2"&gt;Then with the header information, we send the data into the client.&lt;/font&gt;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="580" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="580"&gt;         &lt;pre class="code"&gt;&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="color: green"&gt;Displays data (if exist) as an Excel spreadsheet on user browser.
&lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;bytes&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;The bytes to be the content of the excel spreadsheet&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;DisplayNewExcelFile(&lt;span style="color: blue"&gt;byte&lt;/span&gt;[] bytes)
{
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(bytes == &lt;span style="color: blue"&gt;null &lt;/span&gt;|| bytes.Length == 0)
    {
        litMsg.Text = &lt;span style="color: #a31515"&gt;&amp;quot;No data found.&amp;quot;&lt;/span&gt;;
        &lt;span style="color: blue"&gt;return&lt;/span&gt;;
    }

    Response.ClearHeaders();
    Response.ContentType = &lt;span style="color: #a31515"&gt;&amp;quot;application/vnd.ms-excel&amp;quot;&lt;/span&gt;;
    Page.EnableViewState = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
    Response.AddHeader(&lt;span style="color: #a31515"&gt;&amp;quot;content-disposition&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;attachment;filename=PersonAddress_Modified.xlsx&amp;quot;&lt;/span&gt;);
    Response.BinaryWrite(bytes);

    &lt;span style="color: blue"&gt;try
    &lt;/span&gt;{
        Response.End();
        &lt;span style="color: green"&gt;//this causes a System.Threading.ThreadAbortException, which ends the current request.
    &lt;/span&gt;}
    &lt;span style="color: blue"&gt;catch &lt;/span&gt;{ }
}&lt;/pre&gt;
        &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e67cd7d7-6eec-4080-bd88-dbc71fbb2467" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/ASP.NET" rel="tag"&gt;ASP.NET&lt;/a&gt;,&lt;a href="http://technorati.com/tags/C#" rel="tag"&gt;C#&lt;/a&gt;,&lt;a href="http://technorati.com/tags/How%20to%20display%20Excel%20spreadsheet" rel="tag"&gt;How to display Excel spreadsheet&lt;/a&gt;,&lt;a href="http://technorati.com/tags/View%20Excel%20on%20the%20browser" rel="tag"&gt;View Excel on the browser&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Response%20object." rel="tag"&gt;Response object.&lt;/a&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6716853" width="1" height="1"&gt;</content><author><name>atmacam</name><uri>http://weblogs.asp.net/members/atmacam.aspx</uri></author></entry><entry><title>Server-side Office Integration -5: Inserting data from XML Document</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/mecitatmaca/archive/2008/11/02/office-integration-5-inserting-data-from-xml-document.aspx" /><id>http://weblogs.asp.net/mecitatmaca/archive/2008/11/02/office-integration-5-inserting-data-from-xml-document.aspx</id><published>2008-11-03T02:14:17Z</published><updated>2008-11-03T02:14:17Z</updated><content type="html">&lt;p&gt;We are close to the end of these series. The procedure taking the XML Document as an input parameter, simply look for the nodes in the &lt;strong&gt;'Root/Data'&lt;/strong&gt; path then using its aliases&amp;#160; inserts its values into PersonAddress table. Finally returns the recordsets, just inserted, in its simplest form. Here, we could probably return data as XML document as well. &lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="580" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="580"&gt;         &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;set &lt;/span&gt;ANSI_NULLS &lt;span style="color: blue"&gt;ON
set QUOTED_IDENTIFIER ON
&lt;/span&gt;GO

&lt;span style="color: blue"&gt;CREATE PROCEDURE &lt;/span&gt;[dbo].[ImportPersonAddressXml](
        @XmlDoc xml
)
&lt;span style="color: blue"&gt;AS 

BEGIN

SET NOCOUNT ON
DECLARE &lt;/span&gt;@CurrentDt &lt;span style="color: blue"&gt;datetime&lt;/span&gt;; 
&lt;span style="color: blue"&gt;SET &lt;/span&gt;@CurrentDt = &lt;span style="color: blue"&gt;getDate&lt;/span&gt;();

&lt;span style="color: blue"&gt;BEGIN TRANSACTION

INSERT INTO &lt;/span&gt;Person.Address(AddressLine1, AddressLine2, City, StateProvinceID,
 PostalCode, rowguid, ModifiedDate)    
    &lt;span style="color: blue"&gt;SELECT 
        &lt;/span&gt;P.e.value(&lt;span style="color: #a31515"&gt;'@AddressLine1'&lt;/span&gt;,&lt;span style="color: #a31515"&gt;'nvarchar(60)'&lt;/span&gt;),
        P.e.value(&lt;span style="color: #a31515"&gt;'@AddressLine2'&lt;/span&gt;,&lt;span style="color: #a31515"&gt;'nvarchar(60)'&lt;/span&gt;),
        P.e.value(&lt;span style="color: #a31515"&gt;'@City'&lt;/span&gt;,&lt;span style="color: #a31515"&gt;'nvarchar(30)'&lt;/span&gt;),
        P.e.value(&lt;span style="color: #a31515"&gt;'@StateProvinceID'&lt;/span&gt;,&lt;span style="color: #a31515"&gt;'int'&lt;/span&gt;),
        P.e.value(&lt;span style="color: #a31515"&gt;'@PostalCode'&lt;/span&gt;,&lt;span style="color: #a31515"&gt;'nvarchar(15)'&lt;/span&gt;),
        P.e.value(&lt;span style="color: #a31515"&gt;'@RowGuid'&lt;/span&gt;,&lt;span style="color: #a31515"&gt;'uniqueIdentifier'&lt;/span&gt;),
        @CurrentDt
        &lt;span style="color: blue"&gt;FROM   &lt;/span&gt;@XmlDoc.nodes(&lt;span style="color: #a31515"&gt;'/Root/Data'&lt;/span&gt;) P(e)

&lt;span style="color: blue"&gt;COMMIT TRANSACTION

SELECT &lt;/span&gt;* &lt;span style="color: blue"&gt;FROM &lt;/span&gt;Person.Address &lt;span style="color: blue"&gt;WHERE &lt;/span&gt;ModifiedDate = @CurrentDt

&lt;span style="color: blue"&gt;END&lt;/span&gt;&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:51c152ec-f71b-4a5c-a647-0a28f42d490f" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T-SQL" rel="tag"&gt;T-SQL&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Stored%20Procedure" rel="tag"&gt;Stored Procedure&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Input%20Paramaters" rel="tag"&gt;Input Paramaters&lt;/a&gt;,&lt;a href="http://technorati.com/tags/XML" rel="tag"&gt;XML&lt;/a&gt;,&lt;a href="http://technorati.com/tags/SQL%20Server" rel="tag"&gt;SQL Server&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Import%20Excel" rel="tag"&gt;Import Excel&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Import%20XML%20into%20database" rel="tag"&gt;Import XML into database&lt;/a&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6716661" width="1" height="1"&gt;</content><author><name>atmacam</name><uri>http://weblogs.asp.net/members/atmacam.aspx</uri></author></entry><entry><title>Server-side Office Integration -4: Serializing and De-serializing Excel spreadsheet by using ExcelPackage</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/mecitatmaca/archive/2008/11/02/office-integration-4-serializing-and-de-serializing-excel-spreadsheet-by-using-excelpackage.aspx" /><id>http://weblogs.asp.net/mecitatmaca/archive/2008/11/02/office-integration-4-serializing-and-de-serializing-excel-spreadsheet-by-using-excelpackage.aspx</id><published>2008-11-03T01:54:27Z</published><updated>2008-11-03T01:54:27Z</updated><content type="html">&lt;p&gt;In the previous blog (Office Integration -3), we &lt;strong&gt;serialized&lt;/strong&gt; the excel spreadsheet into a stream object then open a Package on it. Now, according to our scenario, it is time&amp;#160; to do some validation. Since I prefer doing validation on the objects rather than the Package directly, first we &lt;strong&gt;de-serialize&lt;/strong&gt; the stream to the PersonAddress typed objects. Again according to plan; the validation checks:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;if column numbers matches &lt;/li&gt;    &lt;li&gt;if required data exist. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Yes, I agree the validation would be complex in the real world application, however here we focus on Excel package rather Validation. Once the validation passes for &lt;strong&gt;all&lt;/strong&gt; the records, we then serialize the PersonAddress objects back into an XML document. At the end, we will push the XML doc into database stored proc, which will execute importing and returning the records with updated fields (AddressID and ModifiedDate). &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="580" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="580"&gt;         &lt;pre class="code"&gt;&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="color: green"&gt;Transforms the Excel Worksheet into XML document.
&lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;TranslateXlToXmlDocument()
{
    &lt;span style="color: blue"&gt;int &lt;/span&gt;rowCurrent = 1; &lt;span style="color: green"&gt;//excel row index
    &lt;/span&gt;&lt;span style="color: blue"&gt;bool &lt;/span&gt;flgContinue = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
    &lt;span style="color: #2b91af"&gt;XmlElement &lt;/span&gt;root = _xmlDoc.CreateElement(_rootNodeName); &lt;span style="color: green"&gt;//creates root element
    
    &lt;/span&gt;_rowCount = &lt;span style="color: #2b91af"&gt;Convert&lt;/span&gt;.ToInt32(_xlWS.WorksheetXml.SelectSingleNode(&lt;span style="color: #a31515"&gt;&amp;quot;//d:sheetData/d:row[last()]&amp;quot;&lt;/span&gt;, 
        _xlWS.NameSpaceManager).Attributes.GetNamedItem(&lt;span style="color: #a31515"&gt;&amp;quot;r&amp;quot;&lt;/span&gt;).Value);

    &lt;span style="color: green"&gt;//For each data row in the excel worksheet, generate a PersonAddress 
    //Then validate the object against to business rules
    //If fails, then keep running validation check for the rest and omit creating xml document
    //If succeeds, convert the objet into xml element having attributes for each object property then append it.
    &lt;/span&gt;&lt;span style="color: blue"&gt;while &lt;/span&gt;(++rowCurrent &amp;lt;= _rowCount)
    {
        &lt;span style="color: green"&gt;//create PersonAddress object from the xml document
        &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PersonAddress &lt;/span&gt;personAddress = TranslateXlRowToEntity(rowCurrent);&lt;span style="color: green"&gt;//ws index starts with 1 and plus header 
        &lt;/span&gt;ValidateEntity(personAddress, rowCurrent);

        &lt;span style="color: blue"&gt;if &lt;/span&gt;(flgContinue &amp;amp;&amp;amp; _errors.Count &amp;gt; 0)            
            flgContinue = &lt;span style="color: blue"&gt;false&lt;/span&gt;;            

        &lt;span style="color: blue"&gt;if &lt;/span&gt;(flgContinue)
        {
            &lt;span style="color: #2b91af"&gt;XmlNode &lt;/span&gt;node = &lt;span style="color: #2b91af"&gt;ImportUtility&lt;/span&gt;.ConvertToXml&amp;lt;&lt;span style="color: #2b91af"&gt;PersonAddress&lt;/span&gt;&amp;gt;(personAddress, _xmlDoc, _childNodeName);
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(node != &lt;span style="color: blue"&gt;null&lt;/span&gt;)
                root.AppendChild(node);
        }
    }

    &lt;span style="color: blue"&gt;if &lt;/span&gt;(flgContinue)
    {
        _xmlDoc.AppendChild(root);

&lt;span style="color: green"&gt;//#if DEBUG
    &lt;/span&gt;&lt;span style="color: blue"&gt;#region &lt;/span&gt;testing Xml
        &lt;span style="color: blue"&gt;string &lt;/span&gt;strPath = System.Web.Hosting.&lt;span style="color: #2b91af"&gt;HostingEnvironment&lt;/span&gt;.MapPath(&lt;span style="color: #a31515"&gt;&amp;quot;~&amp;quot;&lt;/span&gt;) + &lt;span style="color: #a31515"&gt;@&amp;quot;\App_Data&amp;quot;&lt;/span&gt;; 
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(!&lt;span style="color: #2b91af"&gt;Directory&lt;/span&gt;.Exists(strPath))
            &lt;span style="color: #2b91af"&gt;Directory&lt;/span&gt;.CreateDirectory(strPath);

        &lt;span style="color: blue"&gt;string &lt;/span&gt;path = &lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(strPath, &lt;span style="color: #a31515"&gt;&amp;quot;ExcelToXml.xml&amp;quot;&lt;/span&gt;);
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;File&lt;/span&gt;.Exists(path))
            &lt;span style="color: #2b91af"&gt;File&lt;/span&gt;.Delete(path);

        _xmlDoc.Save(path);
    &lt;span style="color: blue"&gt;#endregion
&lt;/span&gt;&lt;span style="color: green"&gt;//#endif
    &lt;/span&gt;}
}&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;table cellspacing="0" cellpadding="2" width="580" border="1"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="580"&gt;
        &lt;pre class="code"&gt;&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="color: green"&gt;Returns the XML Node generated from the object with T type
&lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;
/// &amp;lt;typeparam name=&amp;quot;T&amp;quot;&amp;gt;&amp;lt;/typeparam&amp;gt;
/// &amp;lt;param name=&amp;quot;t&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;the Object&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
/// &amp;lt;param name=&amp;quot;doc&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;The XML Document&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
/// &amp;lt;param name=&amp;quot;nodeName&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;The Name for the Xml Node &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;XmlNode &lt;/span&gt;ConvertToXml&amp;lt;T&amp;gt;(T t, &lt;span style="color: #2b91af"&gt;XmlDocument &lt;/span&gt;doc, &lt;span style="color: blue"&gt;string &lt;/span&gt;nodeName)
{
    &lt;span style="color: #2b91af"&gt;XmlNode &lt;/span&gt;node = doc.CreateElement(nodeName == &lt;span style="color: blue"&gt;null &lt;/span&gt;? t.GetType().Name : nodeName);

    &lt;span style="color: #2b91af"&gt;PropertyInfo&lt;/span&gt;[] properties = t.GetType().GetProperties();

    &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;PropertyInfo &lt;/span&gt;property &lt;span style="color: blue"&gt;in &lt;/span&gt;properties)
    {
        &lt;span style="color: #2b91af"&gt;XmlAttribute &lt;/span&gt;attr = doc.CreateAttribute(property.Name);
        attr.Value = (property.GetValue(t, &lt;span style="color: blue"&gt;null&lt;/span&gt;) != &lt;span style="color: blue"&gt;null&lt;/span&gt;) ? property.GetValue(t, &lt;span style="color: blue"&gt;null&lt;/span&gt;).ToString() : &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;

        node.Attributes.Append(attr);            
    }
    &lt;span style="color: blue"&gt;return &lt;/span&gt;node;
}&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:01afcf92-10f1-4da8-b30d-55178f3e9a02" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/C#" rel="tag"&gt;C#&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Use%20of%20System.Reflections" rel="tag"&gt;Use of System.Reflections&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Object%20Serialization%20and%20De-serialization" rel="tag"&gt;Object Serialization and De-serialization&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Reading%20&amp;amp;%20writing%20from/to%20XML%20document" rel="tag"&gt;Reading &amp;amp; writing from/to XML document&lt;/a&gt;,&lt;a href="http://technorati.com/tags/XPath" rel="tag"&gt;XPath&lt;/a&gt;,&lt;a href="http://technorati.com/tags/ExcelPackage" rel="tag"&gt;ExcelPackage&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Code%20optimization" rel="tag"&gt;Code optimization&lt;/a&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6716628" width="1" height="1"&gt;</content><author><name>atmacam</name><uri>http://weblogs.asp.net/members/atmacam.aspx</uri></author></entry><entry><title>Server-side Office Integration -3: Use of Excel Package for generating &amp; updating Excel from the server side</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/mecitatmaca/archive/2008/11/02/server-side-office-integration-3-use-of-excel-package-for-generating-amp-updating-excel-from-the-server-side.aspx" /><id>http://weblogs.asp.net/mecitatmaca/archive/2008/11/02/server-side-office-integration-3-use-of-excel-package-for-generating-amp-updating-excel-from-the-server-side.aspx</id><published>2008-11-03T00:58:00Z</published><updated>2008-11-03T00:58:00Z</updated><content type="html">&lt;H3&gt;So What is ExcelPackage really?&lt;/H3&gt;
&lt;P&gt;In short, it is to create and/or modify Excel spreadsheets from the server. To me, it is an open source API that includes classes and &lt;STRONG&gt;wrappers&lt;/STRONG&gt; around &lt;STRONG&gt;.NET 3.0 System.IO.Packaging&lt;/STRONG&gt; class library according to new &lt;STRONG&gt;Open XML&lt;/STRONG&gt; standards. It is called Package because it contains multiple data objects, Worksheets, Worksheet, Row, Cell, Column, Styles, etc... A good example would be Zip file. It is aimed to be a complete solution, however it is still in progress, applying styles, rows cloning, etc waiting for heroes... -Hey it is open source... Thanks &lt;STRONG&gt;Dr. John Tunnicliffe&lt;/STRONG&gt;, for his generous contribution.&lt;/P&gt;
&lt;H3&gt;How does it work?&lt;/H3&gt;
&lt;P&gt;If you look at the System.IO.Packaging namespace, you will see there are different ways of opening a Package. And I am particularly talking about one of them -opening a Package from a stream object:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/mecitatmaca/WindowsLiveWriter/OfficeIntegration3HowtomanipulateExcelda_11EA9/image_4.png" mce_href="http://weblogs.asp.net/blogs/mecitatmaca/WindowsLiveWriter/OfficeIntegration3HowtomanipulateExcelda_11EA9/image_4.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=418 alt=image src="http://weblogs.asp.net/blogs/mecitatmaca/WindowsLiveWriter/OfficeIntegration3HowtomanipulateExcelda_11EA9/image_thumb_1.png" width=624 border=0 mce_src="http://weblogs.asp.net/blogs/mecitatmaca/WindowsLiveWriter/OfficeIntegration3HowtomanipulateExcelda_11EA9/image_thumb_1.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Steps:&lt;/STRONG&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Dump the excel data into a FileStream typed object, &lt;/LI&gt;
&lt;LI&gt;Open a Package object on the stream object, &lt;/LI&gt;
&lt;LI&gt;Construct an Excel worksheet in the package at given index.&amp;nbsp; &lt;/LI&gt;
&lt;LI&gt;Now, we can start all kinds of CRUD (Create, Read, Update, Delete) operations on the worksheet for its rows, columns, cells, styles, properties. Easy right:) &lt;/LI&gt;&lt;/OL&gt;
&lt;TABLE class="" cellSpacing=0 cellPadding=2 width=580 border=1&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top width=580&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;Imports Excel spreadsheet into Database
&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="results"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;The list of errors if any&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;Array of bytes of after excel saved&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/returns&amp;gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public byte&lt;/SPAN&gt;[] ImportExcelData(&lt;SPAN style="COLOR: blue"&gt;out &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;List&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&amp;gt; results)
{
    &lt;SPAN style="COLOR: #2b91af"&gt;DataTable &lt;/SPAN&gt;dt;
    _xmlDoc = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XmlDocument&lt;/SPAN&gt;();
    _errors = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;List&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&amp;gt;();

    _bytes = &lt;SPAN style="COLOR: #2b91af"&gt;File&lt;/SPAN&gt;.ReadAllBytes(_fileName);
    &lt;SPAN style="COLOR: blue"&gt;if &lt;/SPAN&gt;(_bytes == &lt;SPAN style="COLOR: blue"&gt;null &lt;/SPAN&gt;|| _bytes.Length == 0)
        &lt;SPAN style="COLOR: blue"&gt;throw new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Exception&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"No data found in the file. "&lt;/SPAN&gt;);

    &lt;SPAN style="COLOR: #2b91af"&gt;FileInfo &lt;/SPAN&gt;fi = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FileInfo&lt;/SPAN&gt;(_fileName);
    &lt;SPAN style="COLOR: green"&gt;//writes data into filestream object
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;FileStream &lt;/SPAN&gt;fs = fi.OpenWrite())
    {
        fs.Write(_bytes, 0, _bytes.Length);
        fs.Flush();
    }
    
    &lt;SPAN style="COLOR: green"&gt;//create ExcelPackage with fileinfo object created above
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;(_xlPackage = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ExcelPackage&lt;/SPAN&gt;(fi))
    {
        &lt;SPAN style="COLOR: green"&gt;//initialize the excel worksheet object from the excel package at given index.
        &lt;/SPAN&gt;_xlWS = _xlPackage.Workbook.Worksheets[_sheetIndex];

        &lt;SPAN style="COLOR: blue"&gt;if &lt;/SPAN&gt;(_xlWS == &lt;SPAN style="COLOR: blue"&gt;null &lt;/SPAN&gt;|| !_xlWS.WorksheetXml.HasChildNodes)
            &lt;SPAN style="COLOR: blue"&gt;throw new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Exception&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"No worksheet found at given index."&lt;/SPAN&gt;);

        &lt;SPAN style="COLOR: green"&gt;//transforms ExcelWorksheet context to Xml document.
        &lt;/SPAN&gt;TranslateXlToXmlDocument();
        &lt;SPAN style="COLOR: blue"&gt;if &lt;/SPAN&gt;(_errors.Count == 0)
        {
            &lt;SPAN style="COLOR: green"&gt;//inserts XML document into database table
            &lt;/SPAN&gt;dt = InsertXmlData();
            &lt;SPAN style="COLOR: green"&gt;//syncs the excel worksheet with database data
            &lt;/SPAN&gt;UpdateXlWS(dt);
            &lt;SPAN style="COLOR: green"&gt;//accepts changes made to excel worksheet --&amp;gt; excel package.
            &lt;/SPAN&gt;_xlPackage.Save();
        }
    }
    fi.Refresh();
    &lt;SPAN style="COLOR: blue"&gt;byte&lt;/SPAN&gt;[] updatedData = (_errors.Count == 0) ? &lt;SPAN style="COLOR: #2b91af"&gt;File&lt;/SPAN&gt;.ReadAllBytes(fi.FullName) : &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;
   
    results = _errors;
    &lt;SPAN style="COLOR: blue"&gt;return &lt;/SPAN&gt;updatedData;
}&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;DIV class=wlWriterSmartContent id=scid:0767317B-992E-4b12-91E0-4F059A8CECA8:5581eb96-e9f1-48a1-ae03-7f33d7062c53 style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;Technorati Tags: &lt;A href="http://technorati.com/tags/.NET%203.0/3.5" rel=tag mce_href="http://technorati.com/tags/.NET%203.0/3.5"&gt;.NET 3.0/3.5&lt;/A&gt;,&lt;A href="http://technorati.com/tags/C#" rel=tag mce_href="http://technorati.com/tags/C#"&gt;C#&lt;/A&gt;,&lt;A href="http://technorati.com/tags/OpenXML" rel=tag mce_href="http://technorati.com/tags/OpenXML"&gt;OpenXML&lt;/A&gt;,&lt;A href="http://technorati.com/tags/Excel%20Package" rel=tag mce_href="http://technorati.com/tags/Excel%20Package"&gt;Excel Package&lt;/A&gt;,&lt;A href="http://technorati.com/tags/FileInfo" rel=tag mce_href="http://technorati.com/tags/FileInfo"&gt;FileInfo&lt;/A&gt;&lt;/DIV&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6716553" width="1" height="1"&gt;</content><author><name>atmacam</name><uri>http://weblogs.asp.net/members/atmacam.aspx</uri></author><category term="C#" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/C_2300_/default.aspx" /><category term="Open Source" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/Open+Source/default.aspx" /><category term="AJAX" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/AJAX/default.aspx" /><category term="XML" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/XML/default.aspx" /><category term="Import Excel to Database" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/Import+Excel+to+Database/default.aspx" /><category term=".NET 3.0/3.5" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/.NET+3.0_2F00_3.5/default.aspx" /><category term="OpenXML" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/OpenXML/default.aspx" /><category term="ExcelPackage" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/ExcelPackage/default.aspx" /><category term="Application Blcoks" scheme="http://weblogs.asp.net/mecitatmaca/archive/tags/Application+Blcoks/default.aspx" /></entry><entry><title>Server Side Office Integration -2: How to Import Excel Data into Database with ASP.NET?</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/mecitatmaca/archive/2008/10/29/office-integration-2-how-to-import-excel-data-into-database-with-asp-net.aspx" /><id>http://weblogs.asp.net/mecitatmaca/archive/2008/10/29/office-integration-2-how-to-import-excel-data-into-database-with-asp-net.aspx</id><published>2008-10-30T03:47:54Z</published><updated>2008-10-30T03:47:54Z</updated><content type="html">&lt;h3&gt;Intro:&lt;/h3&gt;  &lt;p align="left"&gt;&lt;font face="Verdana" size="2"&gt;In this sample yet robust web-based office integration solution, I have 3 objectives to cover:&lt;/font&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;     &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;How to read excel data &lt;/font&gt;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;How to update &amp;amp; display excel data &lt;/font&gt;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;How to import excel data into database &lt;/font&gt;&lt;/div&gt;   &lt;/li&gt; &lt;/ol&gt;  &lt;h3&gt;Specifications -briefly:&lt;/h3&gt;  &lt;ol&gt;   &lt;li&gt;     &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;User selects an excel file to be imported &lt;/font&gt;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;The application first validates the data against the business rules &lt;/font&gt;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;If fails on validation, the system will display the errors back to the user with a failure message. &lt;/font&gt;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;If succeeds, &lt;/font&gt;&lt;/div&gt;      &lt;ol&gt;       &lt;li&gt;         &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;it transforms the excel data into an XML Document &lt;/font&gt;&lt;/div&gt;       &lt;/li&gt;        &lt;li&gt;         &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;Imports XML data into the database table &lt;/font&gt;&lt;/div&gt;       &lt;/li&gt;        &lt;li&gt;         &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;Update the excel data with the updated records from the database call &lt;/font&gt;&lt;/div&gt;       &lt;/li&gt;        &lt;li&gt;         &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;Pipes new excel file back to the user. &lt;/font&gt;&lt;/div&gt;       &lt;/li&gt;     &lt;/ol&gt;   &lt;/li&gt; &lt;/ol&gt;  &lt;h3&gt;How To Read/Write Excel Data:&lt;/h3&gt;  &lt;p align="left"&gt;&lt;font face="Verdana" size="2"&gt;In my prior post, I have mentioned different ways of doing CRU (Create, Update, Read) operations on an Office document and recommended using Open XML for the purpose. Please see for more details. This samples uses &amp;quot;&lt;a href="http://openxmldeveloper.org/default.aspx"&gt;Open XML&lt;/a&gt;&amp;quot; and &amp;quot;&lt;a href="http://www.codeplex.com/ExcelPackage"&gt;Excel Package&lt;/a&gt;&amp;quot; API's along with core .NET libraries. Let me tell you this, the application also exposes some best practices such as using &lt;a href="http://msdn.microsoft.com/en-us/library/aa480453.aspx"&gt;Enterprise Library (v 3.1)&lt;/a&gt; for data access and logging purposes.&lt;/font&gt;&lt;/p&gt;  &lt;h4&gt;What&amp;#160; you need:&lt;/h4&gt;  &lt;ol&gt;   &lt;li&gt;     &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;.NET 3.0 -minimum, used v3.5 &lt;/font&gt;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;SQL Server (I am using SQL Express) and Adventure Works database installed. &lt;/font&gt;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;Excel Package (Wrapper library for OfficeOpenXML API) &lt;/font&gt;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;Microsoft Enterprise Library 3.1 &lt;/font&gt;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;IDE; used Visual Studio 2008. &lt;/font&gt;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;Browser, used IE 7.0 for testing &lt;/font&gt;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;&lt;font face="Verdana" size="2"&gt;Excel file &lt;/font&gt;&lt;/div&gt;   &lt;/li&gt; &lt;/ol&gt;  &lt;p align="left"&gt;&lt;font face="Verdana" size="2"&gt;&lt;strong&gt;Alright, let's start the show:&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;     &lt;h5&gt;User Interface: &lt;/h5&gt;   &lt;/li&gt; &lt;/ol&gt;  &lt;table cellspacing="0" cellpadding="2" width="680" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="678"&gt;         &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;FileUpload &lt;/span&gt;&lt;span style="color: red"&gt;ID&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;fileUpload&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;server&amp;quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Button &lt;/span&gt;&lt;span style="color: red"&gt;ID&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;btnImportExcel&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;server&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Import Excel Data&amp;quot; 
        &lt;/span&gt;&lt;span style="color: red"&gt;OnClick&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;btnImportExcel_Click&amp;quot; /&amp;gt;    
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;br &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Literal &lt;/span&gt;&lt;span style="color: red"&gt;ID&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;litMsg&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Literal&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;br &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;br &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;GridView &lt;/span&gt;&lt;span style="color: red"&gt;ID&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;gvResults&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;server&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;false&amp;quot; 
        &lt;/span&gt;&lt;span style="color: red"&gt;Caption&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Errors Found&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Visible&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;false&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateField &lt;/span&gt;&lt;span style="color: red"&gt;HeaderText&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;#&amp;quot;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color: blue"&gt;# &lt;/span&gt;Container.DataItemIndex + 1 &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;'
                &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateField&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateField &lt;/span&gt;&lt;span style="color: red"&gt;HeaderText&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Description&amp;quot;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color: blue"&gt;# &lt;/span&gt;Container.DataItem &lt;span style="background: #ffee62"&gt;%&amp;gt;
&lt;/span&gt;                &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateField&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;    
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;GridView&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;table cellspacing="0" cellpadding="2" width="680" border="1"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="680"&gt;
        &lt;pre class="code"&gt;    &lt;span style="color: blue"&gt;#region &lt;/span&gt;Members
    &lt;span style="color: blue"&gt;int &lt;/span&gt;_sheetIndex = 1;  &lt;span style="color: green"&gt;//index of the worksheet (ws) to be imported
    &lt;/span&gt;&lt;span style="color: blue"&gt;int &lt;/span&gt;_headerIndex = 1;  &lt;span style="color: green"&gt;//index of the headers in the ws.
    &lt;/span&gt;&lt;span style="color: blue"&gt;int &lt;/span&gt;_columnCount = 8;
    &lt;span style="color: blue"&gt;#endregion

    #region &lt;/span&gt;Public/Protected Methods
    &lt;span style="color: blue"&gt;protected void &lt;/span&gt;btnImportExcel_Click(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;EventArgs &lt;/span&gt;e)
    {        
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(fileUpload.HasFile)
        {
            &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; errors;
            &lt;span style="color: blue"&gt;string &lt;/span&gt;fileName = fileUpload.PostedFile.FileName;
            &lt;span style="color: blue"&gt;try
            &lt;/span&gt;{
                &lt;span style="color: #2b91af"&gt;ExcelImporter &lt;/span&gt;xlImporter = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ExcelImporter&lt;/span&gt;(fileName, _sheetIndex, _headerIndex, 
                    _columnCount);
                &lt;span style="color: blue"&gt;byte&lt;/span&gt;[] bytes = xlImporter.ImportExcelData(&lt;span style="color: blue"&gt;out &lt;/span&gt;errors);

                &lt;span style="color: blue"&gt;if &lt;/span&gt;((errors == &lt;span style="color: blue"&gt;null &lt;/span&gt;|| errors.Count == 0) &amp;amp;&amp;amp; bytes != &lt;span style="color: blue"&gt;null&lt;/span&gt;)
                {
                    DisplayNewExcelFile(bytes);
                }
                &lt;span style="color: blue"&gt;else
                &lt;/span&gt;{
                    litMsg.Text = &lt;span style="color: #a31515"&gt;&amp;quot;Importing excel data failed.&amp;quot;&lt;/span&gt;;
                    gvResults.DataSource = errors;
                    gvResults.DataBind();
                    gvResults.Visible = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
                }
            }
            &lt;span style="color: blue"&gt;catch &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Exception &lt;/span&gt;ex)
            {
                litMsg.Text = &lt;span style="color: #a31515"&gt;&amp;quot;An unexpected error occurred&amp;quot;&lt;/span&gt;;
                LogError(ex);
            }
        }
    }
    &lt;span style="color: blue"&gt;#endregion
&lt;/span&gt;&lt;/pre&gt;
        &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;h5&gt;&lt;font face="Verdana" size="2"&gt;&lt;/font&gt;&lt;/h5&gt;

&lt;p&gt;Ouch, time for bed. Let's stop here and we will look into business and data access layers in the next sessions.&amp;#160; Bye now.&lt;font face="Verdana" size="2"&gt;&amp;#160;&lt;/font&gt;&lt;/p&gt;

&lt;p align="left"&gt;&lt;font face="Verdana" size="2"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;div align="left"&gt;
  &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:577c6ca7-562f-4f4b-994d-94eb6f25744f" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/.NET%203.0/3.5" rel="tag"&gt;.NET 3.0/3.5&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Enterprise%20Library" rel="tag"&gt;Enterprise Library&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Logging%20&amp;amp;%20Data%20Application%20Blocks" rel="tag"&gt;Logging &amp;amp; Data Application Blocks&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Best%20Practices%20&amp;amp;%20Design" rel="tag"&gt;Best Practices &amp;amp; Design&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Open%20XML" rel="tag"&gt;Open XML&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Excel%20Package" rel="tag"&gt;Excel Package&lt;/a&gt;,&lt;a href="http://technorati.com/tags/C#" rel="tag"&gt;C#&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Codeplex" rel="tag"&gt;Codeplex&lt;/a&gt;,&lt;a href="http://technorati.com/tags/XML" rel="tag"&gt;XML&lt;/a&gt;,&lt;a href="http://technorati.com/tags/XPATH" rel="tag"&gt;XPATH&lt;/a&gt;,&lt;a href="http://technorati.com/tags/SQL" rel="tag"&gt;SQL&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Open%20Source" rel="tag"&gt;Open Source&lt;/a&gt;,&lt;a href="http://technorati.com/tags/AJAX" rel="tag"&gt;AJAX&lt;/a&gt;,&lt;a href="http://technorati.com/tags/JavaScript" rel="tag"&gt;JavaScript&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Design%20literature" rel="tag"&gt;Design literature&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Fun%20stuff" rel="tag"&gt;Fun stuff&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Reflections%20on%20life" rel="tag"&gt;Reflections on life&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Pictures" rel="tag"&gt;Pictures&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p align="left"&gt;&lt;font face="Verdana" size="2"&gt;&lt;/font&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6711302" width="1" height="1"&gt;</content><author><name>atmacam</name><uri>http://weblogs.asp.net/members/atmacam.aspx</uri></author></entry><entry><title>Server-side Office Integration -1</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/mecitatmaca/archive/2008/10/22/office-integration-1.aspx" /><id>http://weblogs.asp.net/mecitatmaca/archive/2008/10/22/office-integration-1.aspx</id><published>2008-10-23T02:21:49Z</published><updated>2008-10-23T02:21:49Z</updated><content type="html">&lt;p&gt;&lt;strong&gt;Abstract:&lt;/strong&gt; By contract, software&amp;#160; applications maybe required to generate or to use one or combination of Office document(s) such as Word Processing, Spreadsheet, and Presentation. Considering this is a huge topic, I will briefly explain this with a small web application that imports an excel spreadsheets content into a database table. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Discussion:&lt;/strong&gt; During my recent projects, I got a chance to learn more about office documents applications. Major drivers in the office applications are Microsoft (MS Office, proprietary), Sun (Star Office) and Google (Google docs) and the sector is getting more and more attention day by day. It seems that practices leaning towards open source &amp;amp; distributed style development. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;How to do server-side Office Integration with DOTNET with minimal coding?&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;I am sure there could be other ways (Bulk Copy/use of DTS) but here are the options (best to my knowledge)&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Use Office Automation (Microsoft.Office): This is requires installation of the automation DLL and it is not recommended for Internet applications. &lt;/li&gt;    &lt;li&gt;Use Open XML formats. MS supports and recommends this with Office 2007. Users who are running earlier versions of Office (such as Office 2000, Office XP, and Office 2003) can view and edit Open XML files if the users install the free compatibility pack download from the Microsoft Web site. One of the best of using Open XML would be the compatibility with non-MS products. &lt;/li&gt;    &lt;li&gt;Use 3rd party components (ExcelReader etc...) or build one yourself. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;As you might see, Open XML is the winner based on flexibility, platform independency, and performance -hoping to report a comparison later on. &lt;/p&gt;  &lt;p&gt;Source link:&amp;#160; &lt;a href="http://support.microsoft.com/kb/257757"&gt;http://support.microsoft.com/kb/257757&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;What is Open XML?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Open XML is a file format for representing office document. Its specification has been approved by ISO/IEC standards. With the recognition/standardization, XML has become de-facto for data exchange, thus an Open XML document consists of multiple data files inthe form of XML.    &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;In the next session, I will provide a sample Internet application integrated with MS Office Excel. &lt;/p&gt;  &lt;p&gt;Let's say cheese for now.   &lt;p&gt;&lt;/p&gt;    &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:a017a4c0-875d-4872-b4b8-3f5a5d52a450" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Open%20Source" rel="tag"&gt;Open Source&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Open%20Office" rel="tag"&gt;Open Office&lt;/a&gt;,&lt;a href="http://technorati.com/tags/XML" rel="tag"&gt;XML&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Excel%20Package" rel="tag"&gt;Excel Package&lt;/a&gt;,&lt;a href="http://technorati.com/tags/.NET%203.5" rel="tag"&gt;.NET 3.5&lt;/a&gt;&lt;/div&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6698734" width="1" height="1"&gt;</content><author><name>atmacam</name><uri>http://weblogs.asp.net/members/atmacam.aspx</uri></author></entry></feed>