Saturday, March 13, 2010

Protect HTML Files

Recently I came up with a requirement to protect a website which was created using HTML.

When searching over the internet a team member of mine found a nice software called HTML Guard.

This software is encoding the source of the site so the users will not be able to see the code behind the site. Using this tool you can even block a site to a particular domain. Even the site is downloaded it will not properly run.

The best thing is this has a free version so we can use the full set of features without paying (A small message will come on the top right corner saying the site is encoded by using the tool).

This software is by WulfSoft, thanks guys you have done a good job.

Try out yourself and see.

http://www.htmlguard.com/

Reading and Writing to Excel Files

Even though I posted similar 2 articles in 2008, the code of that article was having few errors. So thought to put more complete post on this.

The code will read an Excel file using an OleDbConnection and will write the same data back to another Excel file. This will explain how to read and write to Excel files. One thing to remember when running this code is to make sure the source Excel file is open. Otherwise you will get an error similar to “External table is not in the expected format.”

Also note that there are few connection string parameters you can use while opening Excel files.

HDR = Yes – Use when first row contains column headers.

HDR = No  - Use when first row contains data.

Excel xx.x – Use the following Table as a guide.

Parameter Value

Excel Version

Excel 12.0 Excel 2007 (Released in 2007)
Excel 11.0 Excel 2003 (Released in 2003)
Excel 10.0 Excel XP (Released in 2001)
Excel 9.0 Excel 2000 (Released in 1999)
Excel 8.0 Excel 97 (Released in 1997)

 

IMEX=1 – Use this when you want to treat all your data in the file as text.

For example - >

Extended Properties="Excel 12.0 Xml;HDR=YES;IMEX=1";

To make the code to work properly you need to refer the Microsoft.Office.Interop.Excel assembly by adding a reference to your project.





  1. using System;
  2. using System.Data;
  3. using System.Windows.Forms;
  4. using System.Data.OleDb;
  5. using Microsoft.Office.Interop.Excel;
  6. namespace TestApp
  7. {
  8.     public partial class Form1 : Form
  9.     {
  10.         public Form1()
  11.         {
  12.             InitializeComponent();
  13.         }
  14.         private void button1_Click(object sender, EventArgs e)
  15.         {
  16.             openFileDialog1.ShowDialog();
  17.             // Create an OLEDBConnection to connect to the Excel file.
  18.             // I'm getting the required file by using a file dialog.
  19.             // The @ symbol makes the string to contain any special characters inside the string without breaking the string.
  20.             OleDbConnection dbConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + openFileDialog1.FileName.ToString() + @";Extended Properties=""Excel 8.0;HDR=Yes;""");
  21.             // Open the connection.
  22.             dbConnection.Open();
  23.             // Create a command object to work on the data.
  24.             // Note that I have given the sheet name as [Sheet1$] to retrieve data from that named sheet in the particular Excel file.
  25.             OleDbCommand dbCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", dbConnection);
  26.             // Creating a data reader to read data.
  27.             OleDbDataReader dbReader = dbCommand.ExecuteReader();
  28.             // If needed you can get the position of any column (e.g. Age), this will only work if you use HDR=Yes.
  29.             int SearchingItem = dbReader.GetOrdinal("Age");
  30.             // Create the Excel Application object.
  31.             ApplicationClass ExcelApp = new ApplicationClass();
  32.             // Set the visibility of the application.
  33.             ExcelApp.Visible = true;
  34.             // Create a new Excel Workbook.
  35.             Workbook ExcelWorkbook = ExcelApp.Workbooks.Add(Type.Missing);
  36.             // Create a new Excel Sheet.
  37.             Worksheet ExcelSheet = (Worksheet)ExcelWorkbook.Sheets.Add(ExcelWorkbook.Sheets.get_Item(1), Type.Missing, 1, XlSheetType.xlWorksheet);
  38.             // Will keep the current row index. This should start from 1 since the first row is 1.
  39.             int CurrentRowIndex = 1;
  40.             try
  41.             {
  42.                 // Read through the data.
  43.                 while (dbReader.Read())
  44.                 {
  45.                     // Traverse through all the data columns.
  46.                     for (int i = 0; i < dbReader.VisibleFieldCount; i++)
  47.                     {
  48.                         ExcelSheet.Cells[CurrentRowIndex, i + 1] = dbReader.GetValue(i);
  49.                     }
  50.                     CurrentRowIndex++;
  51.                 }
  52.                 // Save the Excel sheet.
  53.                 // The @ symbol makes the string to contain any special characters inside the string without breaking the string.
  54.                 ExcelApp.Save(@"C:\Projects\Ex.xls");
  55.             }
  56.             catch (Exception ex)
  57.             {
  58.                 MessageBox.Show(ex.ToString());
  59.             }
  60.         }
  61.     }
  62. }




Friday, March 05, 2010

Project has Stopped Working

If you create a .NET application to use SQL CE database when you try to run your application on a Windows Vista or Windows 7 machine you might get an error saying your application did stop working, and the error details might show that your are having a problem with System.Data.SQLServerCE.

The reason for this is that your system is not having the SQL Server CE runtime in your machine. To fix it what you need to do is to install the Microsoft SQL Server Compact 3.5 Service Pack 1 on your system. You can download it from the following Microsoft link.

http://www.microsoft.com/downloads/details.aspx?FamilyId=DC614AEE-7E1C-4881-9C32-3A6CE53384D9&displaylang=en

Wednesday, February 17, 2010

An error shown when you try to start the SharePoint Search service

After installing the SharePoint Server when you try to start the search service you might end up with the following error.

An unhandled exception occurred in the user interface.Exception Information: OSearch (Administrator)

or

An unhandled exception occurred in the user interface.Exception Information: OSearch (UserName)

If this comes don’t panic, what you need to do is when providing the username provide it with the full domain name. For example Domain.Local\Administrator.

image

You can find the Microsoft knowledge base article here.

Windows Mobile 7

Highly awaited Windows Mobile 7 is at last showing in horizon.

Have a glance at it by visiting the following URL.

http://www.microsoft.com/presspass/presskits/windowsphone/videoGallery.aspx?contentID=mobileworldcongress2010

http://www.microsoft.com/windowsmobile/en-us/cmpn/windowsphone7series/default.mspx

http://www.windowsphone7series.com/

Microsoft is planning to release phones with Windows Mobile 7 at the end of 2010.

Sunday, February 14, 2010

How Networks Work

I found a really good video which explains how data is travelled in the network. This explains in simple words with animation about the tasks done by the following main components and more.

  • Packet
  • Router
  • Switch
  • Firewall

If anyone is interested in networking I highly recommend you to watch this.

Thursday, February 04, 2010

Making Reliable Connections in BlackBerry Applications

Recently I came up across a blog which provides valuable information on the connections we can make in a BlackBerry application.

If you are interested read more at the following URL.

http://www.localytics.com/blog/post/how-to-reliably-establish-a-network-connection-on-any-blackberry-device/