What’s New In Visual Studio 2010 ASP.NET 4.0

Microsoft has released Visual Studio 2010 and ASP.NET 4.0 beta 1 recently, I felt there are some amazing features which can help developers improve productivity.

Please have look at screen shot of new feature below.

1) New Start page where you have 3 tabs, one is Welcome where we can find welcome note, feedback etc, second tab is project where you can create open projects, third one is Visual Studio tab where you have MSDN, community links

image

2) Target Multiple Versions of .NET: we can build project on different version of .NET versions and also navigation of projects selection is improved.

image

3) Code Snippets: this is one of the best feature I felt in Visual Studio 2010 ASP.NET 4.0, type control name like button and press tab you will button control tag is generated for you similarly when you type script and press tab you will see script tags are created for you.

image

image

4) FormView Improvements, normally when you use FormView Control it will be rendering HTML with Table tag now by default RenderTable = False if you want you can make it True this is still kept for compatible issues.

5) Improved intelligence, now you can filter the intelligence result by pressing Ctrl+Alt+Space

image

image

6) ViewState changes: Now ViewState of a control is by default inherit, that means you can set page level view state and under page all control can inherit its ViewState, if you want to set ViewState to one control separate then you can set for individual control.

This can be done using ViewStateMode = “Inherit” / “Disable” / “Enable”

image

7) ASP.NET provides multiple ways of generating ClientID. You set a way of ClientID in following ways.
Legacy : The ClientID value is generated by concatenating the ID values of each parent naming container with the ID value of the control. In data-binding scenarios where multiple instances of a control are rendered, an incrementing value is inserted in front of the control’s ID value. Each segment is separated by an underscore character (_). This algorithm was used in versions of ASP.NET earlier than ASP.NET 4.0.
Static : The ClientID value is set to the value of the ID property. If the control is a naming container, the control is used as the top of the hierarchy of naming containers for any controls that it contains.
Predictable : This algorithm is used for controls that are in data-bound controls. The ClientID value is generated by concatenating the ClientID value of the parent naming container with the ID value of the control. If the control is a data-bound control that generates multiple rows, the value of the data field specified in the ClientIDRowSuffix property is added at the end. For the GridView control, multiple data fields can be specified. If the ClientIDRowSuffix property is blank, a sequential number is added at the end instead of a data-field value. Each segment is separated by an underscore character (_).
Inherit : The control inherits the ClientIDMode setting of its parent control.

image

These are very few of new features I will be posting more very soon.

Hope this helps

Tags: What’s New in Visual Studio 2010, ASP.NET 4.0

Read & Write ListBox Item into File: Windows Application

Normally some projects will have very small requirement of storing data, so going to have database and storing small amount of data into database is not suitable answer, you can go for storing data into XML or txt file, in following example I am trying to read and write Listbox items into txt file.
I am using Form_Load method to read data from the txt file and on closing the form I am reading all items in the list box and saving them into a txt file with , separator.
Let start building the example.
Create a windows forms applciation and add a List Box, a Text Box and 2 buttons.
Please refer the screen shot : Design.jpg.

design

Make sure that you have created data.txt in c:\logs folder, here I am using C:\logs path you can create any where in the system and change page in the code.
Once you are ready with design and creating txt file, we will add code to read all the items in the text file in Form_Load and also in Form_Closing we will ad code to store all the items in to text file back please refer the code below in screen shot FomLoadUnload.JPG

FomLoadUnload

Once we have added code to read and write to text file now we will add code to add and remove items in the list box, we are using Button2 for removing the items and Button1 for adding the items, please add Click event of Button 1 and 2 to the code, you can refer below code in screen shot AddRemoveItems.JPG

AddRemoveItems

Now we are ready with code just build, run and test

Output

hope this helps.

Using SMOs, Read Tables Script using C#.NET

SQL Server Management Objects (SMOs) are used manipulate database for DBA activities via an application build by you, you can automate some of the DBA tasks by using SMOs in the application.

In this article I am try to explain how we can use SMO to retrieve all the Table listed in Nortwind database and selecting a Table I am display its create script and listing down all the columns in that table.

So lets start create an example how to use SMOs.

Create a Windows Forms application and Add following controls

1) 2 List boxes one is for listing all the tables and one is for listing all the columns in particular table
2) A Text box with multi line mode true and set scrollbars to Vertical

Refer Screen Shot: Design.JPG

Design

Once we have added controls and designed, we need add SMO DLLs for reference so that we can use built-in class.

You need to add following 4 DLL for reference
1) Microsoft.SqlServer.ConnectionInfo
2) Microsoft.SqlServer.Smo
3) Microsoft.SqlServer.SmoEnum
4) Microsoft.SqlServer.SqlEnum

You will find these DLL at following location:
C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies\

Once you have added DLL import them for use, please refer screen shot: References.JPG

References

Now we are ready with our design and references part, so let’s start writing code to get all the Tables in the Northwind Database and add to the ListBox1, for this I have to create a Server object which represents a SQL Server in the machine we need to pass the server name to create that object, here I am creating module level variable so that I can use it in other methods also.

Once you have created server object, you need to get the Database object and Database object will have collection of table, read the Table collection and add Table names to ListBox1, please can refer the code below and also screen shot:Form_Load.jpg

 Form_Load

Now ListBox1 has all the Tables in the Northwind database on selecting any of the table in ListBox1 we want to show all the columns of that table in Listbox2 and also display Create Script of that table in multi line Text box, for that we need to write code in listBox1_SelectedIndexChanged , we create a Table object using selected Table Name in ListBox1 and read all the columns of that table and display in ListBox2, you can refer below code and also screen shot ListColumns.jpg

ListColumns

Now we are ready with our code just build, run and test.

Output

Hope this helps.

Search Files in a Directory : Windows Application

Following example I am trying to search files in a directory using a criteria, using DirectoryInfo.GetFiles() method we can search files with Criteria and you can use * to find all files those are starting with the some string.

So lets start building example, create a windows forms application and add one label, text box, a button and list box, please refer following screen shot

image

Add following function to Form1 which takes Search Text as file name and Folder Path where files needs to be searched, In following function I am taking FileName as search text and DirectoryName as folder path and searching the files

image

Double click on Search button add following code, following code I am simply taking the search text and selecting folder path and passing to the above function

image

Now we are ready with Code, lets build, run and test

Output:

image

Tag: DirectoryInfo, FileInfo, C#, Windows Application, Search Files

TechEd 2009 India Experience

I have attended Microsoft TechEd 2009 at Hyderabad HICC from 13 to 15 May 2009; it was great experience and a great chance to learn new technologies.

Day 1 Experience:
It was awesome to Steve Ballmer speaking at TechEd, he mentioned about present and future opportunities in the market and he mentioned that we need to be more productive in the financial situation, do more with less will help us to come out from the present situation. He also mentioned that being innovative will help us go gain more opportunities. Day 1 I also attended Stephen Walther’s presentation what‘s new in ASP.NET 4.0

Day 2 Experience:
Attended Stephen Walther’s Presentation what’s New in ASP.NET AJAX 4.0, I also personally speak to him and had a photograph with him.

Day 3 Experience:
Attended Presentations on Sliver Light and also some of SQL Server 2008 presentation and those were very informative.

Tags: TechEd 2009 India

SQL Server 2008 Developer Training Kit Available

The training kit offers the following benefits:
Learn how to build web applications that exploit the unique features and capabilities of SQL Server 2008.
Provides a comprehensive set of presentations, demos and hands-on labs
Designed for web developers who are already familiar with SQL Server application development.
Easy to download and install and works on free editions of SQL Server 2008 and Visual Studio 2008.

Produced by Southworks SRL, a well-known provider of evangelism content, using both existing and new content custom developed for this training kit.
Software Requirements
The following software is not included with the training kit and must be downloaded and installed separately. 

SQL Server 2008 Express with Advanced Services (or higher-level SKU)
Microsoft Visual Web Developer 2008 Express (or higher-level SKU)
AdventureWorks 2008 Sample Databases

The training kit is available at the following URL: SQL Server 2008 Developer Training Kit
 

SQL Server 2008, Learn, Training Kit, SQL Server 2008 Learning Videos

Export DataGridView into .csv file

Following example I am trying to save the DataGridView’s Data into .csv file

Please create a Windows Application and Add a DataGridView and a button on Form1, to fill the data initially please add following code in Form1_Load

image

Double click on the Button and add following code in Button1_Click, in this code we are reading all columns and rows and forming a string and saving in data.csv file

image

Now we are ready with our code, just build, run and test.

Tags: Export DataGridView to .csv file, Windows Forms, C#, .NET