Since MSDN forums started they have captured substantial share of online forums related to Microsoft technologies. I remember having a discussion with one of the softies about newsgroups and how MSDN forums will eventually replace them (in MS world of course). And now you can interact with Microsoft forums using a client application which is available as a CTP here.

To install Microsoft forums you must have WindowsLiveID Client SDK installed on your machine.
If there is one book I am looking forward to, it is Microsoft Visual Studio Tips by Sara Ford . I am a regular reader of Sara’s blog and I have learned a lot about Visual Studio by reading her blog. Her tips are simple, lightweight but above all very++ useful.
I expect her book to be icing on the cake. Maybe she will surprise readers by giving us more practical rubber hits the road kind of treat.
|
Microsoft® Visual Studio® Tips (PRO-Developer) by Sara Ford |
Two senior engineering managers for Windows 7, Jon DeVaan and Steven Sinofsky have started a blog called Engineering Windows 7. I am sure that this will be one of the most watched blogs till other Windows 7 related blogs/sites appear. Reading their first post I get an impression that their blog is an attempt to engage community/customers in a conversation around next version of Windows.
We strongly believe that success for Windows 7 includes an open and honest, and two-way, discussion about how we balance all of these interests and deliver software on the scale of Windows. We promise and will deliver such a dialog with this blog.
I am eagerly looking forward to interesting posts on E7 blog.
SQLBulkCopy class in ADO.NET can be used to do bulk copy operations from a .Net application. There are two ways data can be bulk copied using this class. You can either do a single bulk copy or a multiple bulk copy operation. In this post I will show you how to perform a single bulk copy operation. I will copy all data in [order details] table from one Northwind database to another. Before running the code I have already cleared the [order details] table in destination database using a truncate statement.
Here is a complete sample which copies data from my Northwind database to Northwind2 database:
static void Main(string[] args)
{
/******************************************************************
* Bulk copy Order Details data from Northwind to Northwind2 database
*****************************************************************/
string northwindConnectionString =
"Data Source=.;Initial Catalog=Northwind;Integrated Security=True";
string northwind2ConnectionString =
"Data Source=.;Initial Catalog=Northwind2;Integrated Security=True";
using (SqlConnection northwindConnection =
new SqlConnection(northwindConnectionString))
{
northwindConnection.Open();
SqlCommand command =
new SqlCommand("Select * from [order details]", northwindConnection);
SqlDataReader dataReader = command.ExecuteReader();
using (SqlConnection northwind2Connection =
new SqlConnection(northwind2ConnectionString))
{
northwind2Connection.Open();
SqlBulkCopy bulkCopy = new SqlBulkCopy(northwind2Connection);
bulkCopy.DestinationTableName = "[Order Details]";
bulkCopy.WriteToServer(dataReader);
northwind2Connection.Close();
}
northwindConnection.Close();
}
Console.WriteLine("Bulk Copy Operation Successful");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
While executing the above code, I also ran profiler to see the generated statements. SQLBulkCopy produced the following SQL statement for this bulk copy operation.
insert bulk [Order Details] ([OrderID] Int,
[ProductID] Int,
[UnitPrice] Money,
[Quantity] SmallInt,
[Discount] Real)
SQLBulkCopy is a fast efficient way to do bulk copy operations. It is useful when you are handling large amount of data for simple operations such as copying from one location to another.
How can we find duplicate occurrences of values in a collection? I will demonstrate this here using a collection of cities. City class looks like this:
public class City
{
public string Name { get; set; }
public string Country { get; set; }
}
Cities collection is initialised with this code:
List<City> cities =
new List<City>
{
new City{ Name = "Sydney", Country = "Australia" },
new City{ Name = "Sydney", Country = "Australia" },
new City{ Name = "New York", Country = "USA" },
new City{ Name = "Paris", Country = "France" },
new City{ Name = "Milan", Country = "Spain" },
new City{ Name = "Melbourne", Country = "Australia" },
new City{ Name = "Auckland", Country = "New Zealand" },
new City{ Name = "Tokyo", Country = "Japan" },
new City{ Name = "New Delhi", Country = "India" },
new City{ Name = "Hobart", Country = "Australia" },
new City{ Name = "Boston", Country = "USA"}
};
Objective is to find countries which occur more than once in the collection and while I am doing that I would also like to know the number of cities for that country. To do this I can use this query. I am using a foreach loop to output my results.
var query =
from c in cities
group c by c.Country into g
where g.Count() > 1
select new { Country = g.Key, CityCount = g.Count()};
foreach (var item in query)
{
Console.WriteLine("Country {0} has {1} cities", item.Country, item.CityCount);
}
By running the above query I get this output which is correct as there are only two countries in the collection which have more than one city.
![]()
You may have noticed from my blog posts lately that these days I am spending considerable time working with LINQ. Although I mainly concentrate on LINQ To Objects and LINQ To XML, I often wander around and play with other flavors of LINQ as well. Today, just out of curiosity I wanted to see how many flavors of LINQ are out there. And I found many. So here is a list of different LINQ flavors available at present. Some of these are work in progress.
- LINQ To Objects
- LINQ To XML
- LINQ To SQL
- LINQ To Flickr
- LINQ To Amazon
- LINQ To Google
- LINQ To LDAP
- LINQ To NHibernate
Am I missing any?
While working, you will always find two things running on my machine. One is without any doubt Visual Studio and second is MSDN Library. Since this morning after installing Visual Studio 2008 SP1 I’ve been trying to get my hands on the latest MSDN Library. Thanks to Iftekhar who pointed me to the latest MSDN Library.
Download link for the latest MSDN Library For Visual Studio SP1. This will download an iso file.
Introduction
At times us developers have to deal with delimited text files in our applications. Such files have been around since yonks and I often come across data import/export tasks where delimited files are used. Till now the common way in .NET has been to read each line and then extract data using some sort of creative string functions within for loops. But there is another way by using LINQ. In this tutorial I will show you how to use LINQ to read such data. By the end of tutorial you will appreciate how easy and logical it is to use LINQ for reading data from delimited text files.
Sample Data
I will use a sample file which contains a data about customers. When working with text files we must know the number of columns and the data contained in each column. Below is a list of columns in their right order for our file.
- First Name
- Last Name
- Job Title
- City
- Country
The file itself will contain this data. I have pulled this out of Employees table in Northwind database.

Reading Data
Before we start reading our csv file we will create a class which will hold a record we will read from our csv file. For this I will create a customer class which looks like this. I know I pulled data from Employees table so just imagine that data above is customer data. Employees can also be customers ;)
public class Customer
{
string Firstname { get; set; }
string Lastname { get; set; }
string JobTitle { get; set; }
string City { get; set; }
string Country { get; set; }
}
Reading Entire File
Now we are ready to read data from our file using LINQ. Using this code we can read the entire file. I am also using a foreach statement to output the results.
var query =
from line in File.ReadAllLines(filePath)
let customerRecord = line.Split(',')
select new Customer()
{
Firstname = customerRecord[0],
Lastname = customerRecord[1],
JobTitle = customerRecord[2],
City = customerRecord[3],
Country = customerRecord[4]
};
foreach (var item in query)
{
Console.WriteLine("{0}, {1}, {2}, {3}, {4}",
item.Firstname, item.Lastname, item.JobTitle, item.City, item.Country);
}
File.ReadAllLines() returns an array of lines and we then use the split function of array to split it by a comma. Its just that simple.
Reading selected records
We can use this code to read all customers who live in UK.
var query =
from c in
(from line in File.ReadAllLines(filePath)
let customerRecord = line.Split(',')
select new Customer()
{
Firstname = customerRecord[0],
Lastname = customerRecord[1],
JobTitle = customerRecord[2],
City = customerRecord[3],
Country = customerRecord[4]
})
where c.Country == "UK"
select c;
This code can be used to read customers who have sales in their job title.
var query =
from c in
(from line in File.ReadAllLines(filePath)
let customerRecord = line.Split(',')
select new Customer()
{
Firstname = customerRecord[0],
Lastname = customerRecord[1],
JobTitle = customerRecord[2],
City = customerRecord[3],
Country = customerRecord[4]
})
where c.JobTitle.Contains("Sales")
select c;
I am sure that above queries can be polished by using a bit more syntax sugar but I am just too excited to see LINQ working with a csv file.
Conclusion
LINQ makes it extremely simple to work with delimited text files. Once we have the records from a csv file in an object we can use all the power of LINQ to query our hearts out on such files. This functionality is available to us via LINQ to objects and we do not need another flavour of LINQ to achieve this. Stay tuned for more posts on LINQ.

Microsoft provides a Creative Commons addin for Microsoft Office 2007. This addin allows authors to embed CC licenses into Excel, Word and PowerPoint. After installing the addin you will see a new tab on the Ribbon.
Yippeee! SP1 for .Net 3.5 and Visual Studio 2008 has been released. This service pack includes ADO.NET Entity Framework and ADO.NET Data Services. There are WPF designer improvements and WPF performance improvements. You can find more details and download link here.
Finally I can now install SQL Server 2008 without disturbing the apple cart :)
Back in may I posted Part 1 of this series on my old blog. Looking at the statistics it turned out to be one of the highly visited post. Recently I also had a comment asking me when I was publishing other parts of study links. Continuing the same trend here is the second part of this series.
Building user interfaces
Select and configure content controls
- Controls Overview
- Controls by Category
- Content Control Class (Also read about all controls that inherit from ContentControl)
Select and configure layout panels
- The Layout System
- A Guided Tour of WPF – Part 2 (Layout)
- WPF Layout Basics
- Layout in Windows Presentation Foundation
Integrate Windows Forms controls into a WPF application
- WindowsFormsHost Class
- ElementHost Class
- WPF vs. Windows Forms (read this to get an understanding of both sides)
- WinForms and WPF Interop – The Best of Both Worlds
- Walking Through Avalon and Windows Forms Interoperability in Code (This article is a bit old but anything goes for shameless self promotion :))
- Windows Forms Interop with WPF (Screencast)
Create user and custom Controls
- Creating Custom WPF Controls
- WPF Custom Control Dependency Property Gotcha
- How to Add Commands to Custom WPF Control
- Recommended practices for WPF Custom Control developers (old source but still relevant)
- Initializing controls within your WPF custom control template (good tip)
These links should get you started with Building User Interfaces skills requirement for Exam 70-502 TS: Microsoft .NET Framework 3.5 – Windows Presentation Foundation Application Development
Top Posts
- LINQ To SQL Tutorial
- LINQ To SQL Join On Multiple Conditions
- Code Sample: Programmatically Download File Using C#
- Windows 7 Control Panel In Classic Mode
- More Details Emerge On Microsoft Master Certification
- Use SqlConnection With LINQ To SQL
- Free Icons And Images With Visual Studio 2008
- Capture XML In WCF Service
- Dynamic Sort With LINQ
- StyleCop Tutorial
Tags
.Net 2010 ADO.NET ASP.NET Azure Blogging Books Browsers C# Certification Cloud Computing Code Snippets Community Data Services Eclipse Entity Framework Google IDE Java LINQ Mac Microsoft Museum NetBeans Office Oracle REST SharePoint Silverlight SQL Server T-SQL Tips Tools Training Visual Studio Visual Studio 2010 WCF Web Windows Windows 7 Windows Forms Windows Live WMI WPF XAML



