Monthly Archives: February 2011

Copy paste from Excel into a DataTable

Ever wanted to copy and paste from Excel into a System.Data.DataTable for displaying in a DataGrid? Here’s some quick and dirty code to do just that :- private void PasteFromExcel()         {             DataTable tbl = new DataTable();             tbl.TableName = “ImportedTable”;             List<string> data = new List<string>(ClipboardData.Split(‘\n’));             bool firstRow = true;             if (data.Count > 0 && string.IsNullOrWhiteSpace(data[data.Count – 1]))             {                 data.RemoveAt(data.Count – 1);             }             foreach (string iterationRow in data)             {                 string row = iterationRow;                 if (row.EndsWith(“\r”))                 {                     row = row.Substring(0, row.Length – “\r”.Length);                 }                 string[] rowData = row.Split(new char[] { ‘\r’, ‘\x09’ });                 DataRow newRow = tbl.NewRow();                 if (firstRow)                 {                     int colNumber = 0;                     foreach (string value in rowData)                     {                         if (string.IsNullOrWhiteSpace(value))                         {                             tbl.Columns.Add(string.Format(“[BLANK{0}]”, colNumber));                         } […]

Custom WebBrowser Control with Zooming and CSS Injection

I thought I would post this custom browser I wrote for a project I am working on. It allows you to access the zoom function of the Internet Explorer browser (AxWebBrowser) by calling a Zoom method (passing in a whole number, expressed as percentage). I also added an InjectCSS() method which allows you to insert […]

Streaming Files (for Upload/Download) in WCF (Message Contracts)

I recently had to write some code to perform an upload to a WCF service, and there was a chance that the files could be a touch on the large side so streaming seemed like the best option. There is quite a limited amount of information about this subject – and configuring the web config […]