RSS

Compare and update XML File with the changes

Thu, Oct 30, 2008

0 Comments

Recently I had a requirement to compare 2 XML Files, which has the existing and new settings of an application stored in them. what I wanted to do is when a new XML file of settings is arrived, I had to compare and retain the existing settings, and add any new ones if there are any, remove any settings if they are removed in the new one. Mainly I needed to compare nodes as well as attributes.

Here are few suggestion I got from my friends and communities:

  1. XML Diff Patch - Couldn’t achieve what I wanted.
  2. Linq for XML -  I cannot use this as the application is developed under .net Framework 2.0

 

So after Several Discussions and Forum Posts I Decided to Write one on my own. I don’t know whether it is the best, but it servers for my purpose. so just thought of sharing it with you all, as I saw there were a lot with the same problem. I know  it needs some improvements such as comparing nested nodes and attributes. but  this would be a better kick start. "something is better than nothing" right!!!.

 

Here are two sample XML files which we can use for our comparison, and the output expected.

 

Existing Settings

<Properties xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Property Name="PerformanceType1" ProID="1" Text="Gross"
 Type="ddlb" Values="On|Off">On</Property>
    <Property Name="Benchmark1" ProID="3" Text="Benchmark 1" Type="ddlb"
 Values="N/A|2nd Security Index">N/A</Property>
    <Property Name="Benchmark2" ProID="4" Text="Benchmark 2" Type="ddlb"
 Values="N/A|2nd Security Index">N/A</Property>
    <Property Name="Region1" ProID="7" Text="Column 1" Type="ddlb" 
Values="N/A|1 Month|2 Month|3">1 Month</Property>
    <Property Name="FromDate1" ProID="8" Text="Column 1 From" 
Type="Date">N/A</Property>
    <Property Name="FromDate9" ProID="24" Text="Column 9 From" 
Type="Date">N/A</Property>
</Properties>

 

New Settings

<Properties xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance 
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Property Name="PerformanceType1" ProID="1" Text="Gross"
 Type="ddlb" Values="On|Off">On</Property>
    <Property Name="Benchmark1" ProID="3" Text="Benchmark 1" 
Type="ddlb" Values="N/A|2nd Security Index">changed</Property>
    <Property Name="Benchmark2" ProID="4" Text="Benchmark 2" 
Type="ddlb" Values="N/A|2nd Security Index">N/A</Property>
    <Property Name="Region1" ProID="9" Text="Changed" 
Type="ddlb" Values="N/A|1 Month|2 Month|3">1 Month</Property>
    <Property Name="NewData" ProID="29" Text="Column 9 From" 
Type="Date">NewlyAdded</Property>
    <Property Name="FromDate9" ProID="24" Text="Column 9 From" 
Type="Date">N/A</Property>
</Properties>
 
Expected Output
 
<Properties xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Property Name="PerformanceType1" ProID="1" Text="Gross" 
Type="ddlb" Values="On|Off">On</Property>
    <Property Name="Benchmark1" ProID="3" Text="Benchmark 1"
 Type="ddlb" Values="N/A|2nd Security Index">N/A</Property>
    <Property Name="Benchmark2" ProID="4" Text="Benchmark 2"
 Type="ddlb" Values="N/A|2nd Security Index">N/A</Property>
    <Property Name="Region1" ProID="9" Text="Changed"
 Type="ddlb" Values="N/A|1 Month|2 Month|3">1 Month</Property>
    <Property Name="FromDate9" ProID="24" Text="Column 9 From"
 Type="Date">N/A</Property>
    <Property Name="NewData" ProID="29" Text="Column 9 From"
 Type="Date">NewlyAdded</Property>
</Properties>
 
 
 

And now Lets see how the code works:

 
string original = File.ReadAllText(@"<Original File path>");
string New = File.ReadAllText(@"<New File path>");
XmlCompare compare = new XmlCompare();
XmlDocument docs=compare.compare(original, New);
File.WriteAllText(@"<output path>", docs.OuterXml);
 
 

The Implementation of the code and its functionality is given in the below download file, with inline comments.

Please note few values are hard coded in this class, but can be altered to suit the requirements.

XMLCompare.cs

I hope it helps for a kick start!.

 

 
Continue reading...

The FILESTREAM Data Type in SQL Server 2008

Wed, Sep 24, 2008

0 Comments

Seriously, i’ve no time these days for blogging, busy with work as well as personal activities. but just wanted to share this valuable information for those who might have missed.

Well the current project which im working on is the ASSETTE Presentations. for more information on the project you can see the above link. but the project uses alot of binary data transfered back and forth to the server and the client thorugh our web services, and most of these binary files are stored in SQL Server 2005 Database. storing binary files inside the database really slows down retrieval of the files when we need them and there are several other desadvantages also. specially  rapidly growing size of the database,taking backups, and maintainance of the database. 

But now with SQL Server 2008 we have a new data type called FILESTREAM , to solve all the above issues.

 

What is FILESTREAM?

FILESTREAM is a new datatype in SQL SERVER 2008. To use FILESTREAM, a database needs to contain a FILESTREAM filegroup and a table which contains a varbinary(max) column with the FILESTREAM attribute set. This causes the Database Engine to store all data for that column in the file system, but not in the database file. A FILESTREAM filegroup is a special folder that contains file system directories known as data containers. These data containers are the interface between Database Engine storage and file system storage through which files in these data containers are maintained by Database Engine.

What FILESTREAM does?

By creating a FILESTREAM filegroup and setting a FILESTREAM attribute on the column of a table, a data container is created which will take care of DML statements.

FILESTREAM will use Windows API for streaming the files so that files can be accessed faster. Also instead of using SQL SERVER cache it will use Windows cache for caching the files accessed.

When you use FILESTREAM storage, consider the following:

  • When a table contains a FILESTREAM column, each row must have a unique row ID.
  • FILESTREAM data containers cannot be nested.
  • When you are using failover clustering, the FILESTREAM filegroups must be on shared disk resources.
  • FILESTREAM filegroups can be on compressed volumes.
For more information on how to use FILESTREAM and to have a in depth knowladge about it please refer the below article in SQLSERVERCENTRAL. its well written and gives you a clear idea on what it is.
The FILESTREAM Data Type in SQL Server 2008
By Deepa Gheewala, 2008/09/24
and here is another blog post on the same topic in MSDN Blogs.
Hope It helps!.

 

 

Continue reading...

44 Silverlight 2.0 Videos

Sat, Aug 2, 2008

1 Comment

Are you searching  for webcasts to learn about Microsoft Silverlight 2.0 ? well then, here is a good news for you all.Mike Taulty recently uploaded and amazing collection of Silverlight 2.0 screencasts on how Silverlight works, controls, File IO, networking, UI design,  data-binding, interacting with HTML pages, and more.if you want to have a good start on Silverlight, then go get them!. it will help you for sure.

silverlight

  1. Silverlight - Hello World
  2. Silverlight - Anatomy of an Application
  3. Silverlight - The VS Environment
  4. Silverlight - Content Controls
  5. Silverlight - Built-In Controls
  6. Silverlight - Width, Height, Margins, Padding, Alignment
  7. Silverlight - Using a GridSplitter
  8. Silverlight - Grid Layout
  9. Silverlight - StackPanel Layout
  10. Silverlight - Canvas Layout
  11. Silverlight - Databinding UI to .NET Classes
  12. Silverlight - Simple Styles
  13. Silverlight - Custom Types in XAML
  14. Silverlight - Binding with Conversion
  15. Silverlight - List Based Data Binding
  16. Silverlight - Simple User Control
  17. Silverlight - Templating a Button
  18. Silverlight - Resources from XAP/DLL/Site Of Origin
  19. Silverlight - Animations & Storyboards
  20. Silverlight - Uploads with WebClient
  21. Silverlight - Downloads with WebClient
  22. Silverlight - Calling HTTPS Web Services
  23. Silverlight - Calling Web Services
  24. Silverlight - Making Cross Domain Requests
  25. Silverlight - Using HttpWebRequest
  26. Silverlight - File Dialogs and User Files
  27. Silverlight - Using Sockets
  28. Silverlight - Using Isolated Storage
  29. Silverlight - .NET Code Modifying HTML
  30. Silverlight - Using Isolated Storage Quotas
  31. Silverlight - Calling JavaScript from .NET
  32. Silverlight - Evaluating JavaScript from .NET Code
  33. Silverlight - Handling HTML Events in .NET Code
  34. Silverlight - Handling .NET Events in JavaScript
  35. Silverlight - Calling .NET from JavaScript
  36. Silverlight - Displaying a Custom Splash Screen
  37. Silverlight - Passing Parameters from your Web Page
  38. Silverlight - Loading Media at Runtime
  39. Silverlight - Dynamically Loading Assemblies/Code
  40. Silverlight - Reading/Writing XML
  41. Silverlight - Multiple Threads with BackgroundWorker
  42. Silverlight - Insert/Update/Delete with the DataGrid
  43. Silverlight - Getting Started with the DataGrid
  44. Silverlight - Embedding Custom Fonts
    Thats it!. Have  a great weekend!!.

Continue reading...

Create Excel Sheets Programmatically with C# without Installing Excel.

Fri, Jul 25, 2008

2 Comments

Here goes one more needy component for developers. a lot of developers always had a problem of exporting data to excel programmatically. if you Google this topic you will get many results regarding this. here are some which caught my eyes.

  1. How To Use ADO.NET to Retrieve and Modify Records in an Excel Workbook With Visual Basic .NET
  2. DataSet to Excel in Two steps – with Different Styles- by Krishna_accent
  3. And finally comes our good old CSV files.

the first one seems to be ok. but have little more work to be done on coding. the second is a  really good one, but again we need excel to be installed, which again run out of our needs.

using CSV is ok for unformatted Comma Separated Values.

 

But Recently I found Carlos Aguilar Mares has this wonderful FREE component called ExcelXmlWriter , to export data to excel. it doesn’t need excel to be installed and it can be used to generate formatted excel workbooks with very few lines of code.

 

   1:  using CarlosAg.ExcelXmlWriter;
   2:   
   3:  class TestApp {
   4:      static void Main(string[] args) {
   5:          Workbook book = new Workbook();
   6:          Worksheet sheet = book.Worksheets.Add(“Sample”);
   7:          WorksheetRow row =  sheet.Table.Rows.Add();
   8:          row.Cells.Add(“Hello World”);
   9:          book.Save(@”c:\test.xls”);
  10:      }
  11:  }

the download has a very easy to understand help file explaining how to use this. you can download it in his website here.

Clean and simple isn’t it ?

Continue reading...

Create PDF Files on the fly with C# and PDFSharp

Thu, Jul 24, 2008

5 Comments

Recently one of my colleague asked me is there anyway to programmatically merge huge number of PDF  files in to a single file, without using Adobe Acrobat libraries, well the answer is yeah. and there are a lot of off the shelve and open source libraries available for this. the best one I found is the PDFSharp, and its totally FREE.

Here is a little introduction about PDFSharp:

  • PDFsharp is the Open Source library that easily creates PDF documents from any .NET language.
    The same drawing routines can be used to create PDF documents, draw on the screen, or send output to any printer.
  • It can use either GDI+ or WPF.
  • It includes support for Unicode in PDF files.
  • It also includes MigraDoc Lite which brings you all the high-level functionality not included in PDFsharp.

Using PDFSharp is very simple. the samples in the official download file are more than enough to learn the functionality of PDFSharp.here is a little piece of code I used to merge A collection of PDFs in a folder to a single PDF file.

   1:  PdfDocument inputDocument=
   2:                  PdfReader.Open(file.FullName,PdfDocumentOpenMode.Import);
   3:  int count = inputDocument.PageCount;
   4:    for (int idx = 0; idx < count; idx++)
   5:     {
   6:         // Get the page from the external document…
   7:         PdfPage page = inputDocument.Pages[idx];
   8:         // …and add it to the output document.
   9:         outputDocument.AddPage(page);
  10:     }
  11:  
  12:  outputDocument.Save(filename);

if you want to download the full sample I created download it  here.

if you want to download pdfSharp Library visit the site below:

http://www.pdfsharp.com/PDFsharp

Continue reading...

IIS and Skype : IIS: The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0×80070020)

Fri, Apr 25, 2008

2 Comments

 

I just came back from work few hours ago. and i received a call from my PM about some issue, and it was on a web application running on  HTTPS (SSL).  so I tried to create a local application with SSL in my local IIS for testing purpose. ( to know how to create SSL sites in local IIS 7 see here.

well everything went well but I couldn’t start the HTTPS site because i got the following error:

caps

After some Google search, and tracing my ports through netstat, i found out it was caused because of Skype. if you have Skype installed here is the way to resolve it.

All you have to do is go to Skype –> Tools—> options.

And under Advance tab click connection and you will see a screen similar to picture below. just deselect the highlighted option and save and restart your Skype. And start the SSL site in IIS. That’s all you’re ready to go with your SSL site through https://localhost.

caps2

Continue reading...

FREE - Visual Studio 2008 Professional Edition & Expression Studio For Students

Thu, Apr 17, 2008

2 Comments

Well Last February Microsoft Announced Dreamspark. which provides free downloads of professional developer tools for students. but it seems a lot of students doesnt know about it. so i thought i could inform you all, in case if you had missed it.

DreamSpark is simple, it’s all about giving students Microsoft professional-level developer and design tools at no charge so you can chase your dreams and create the next big breakthrough in technology - or just get a head start on your career.

Here are some of the products it gives for free :)

For more info visit Dreamspark Home here.

Continue reading...

MSDN Reader!! A Must Have Application!

Tue, Feb 26, 2008

0 Comments

www.windowsclient.net have released a new "Syndicated Client Starter Kit" designed to make it easy to create rich, syndicated multimedia and content experiences which engage the user, from documents and photos to videos and podcasts.you can read the story here.

And this Starter Kit Show case includes an awsum MSDN Reader. The MSDN Reader allows you to browse through MSDN Magazine articles like never before. Read through articles, view figures and code snippets in an intuitive and easy-to-use experience. The complete source code for the reader is also provided for us to download here.

Its totally free. and I would say its a must have for we developers. so what are you waiting for install it!

Download it here
Source Code
Syndication Starter Kit home

Continue reading...
Older Entries