Adrian Martinez\’s Blog

For your information

Visual Studio 2008 and .NET Framework Training Kit Review

Filed under: VisualStudio — at 11:38 pm on Tuesday, January 8, 2008

I have been reviewing the Visual Studio 2008 and .NET Framework Training Kit that is available for download in

http://www.microsoft.com/downloads/details.aspx?FamilyID=8bdaa836-0bba-4393-94db-6c3c4a0c98a1&DisplayLang=en

It contains 5-days of technical content including 20 hands-on labs, 28 presentations, and 20  demo-scripts. It is great!

I would like to recommend you the following hands-on labs I have liked the most to get you quickly introduced into the following new technologies

Technology Lab Recommendation
C# 3.0 What´s new in C# 3.0? This is good to learn the new capabilities of this language by doing small exercises for each new feature
Visual Basic 9 What´s new in Visual Basic 9? Great to learn the new outstanding support of XML in Visual Basic 9
ASP.NET AJAX Introduction to ASP.NET AJAX This lab is a very good one to get introduced into the ASP.NET AJAX world. It also shows how to consume a WCF service from AJAX client side.
Silverlight Silverlight Monster Factory: Using a XAML Template An awesome and very funny lab to start learning Silverlight. It also teaches you to use some Microsoft Expression Designer´s features
Windows Client Services Client Application Services This Lab provides a good way to start using the Membership, Role providers, Working Offline, and many more cool features
Visual Studio Tools for Office System Create an Outlook Add-in with a Form Region This lab has a very useful example of how to add an Outlook Addin to have access to data inside a database without switching the application.

Scott Guthrie has posted about this training kit in his link-listing series in his blog at http://weblogs.asp.net/scottgu/archive/2008/01/04/jan-4th-links-asp-net-asp-net-ajax-asp-net-mvc-visual-studio-iis7.aspx

Setup your enviroment for free!

If you want to try this training kit and the above labs for free I suggest getting

And to run these labs remember to run the SetupEx.cmd at first which is in every lab folder.

Cheers!

Windows PowerShell basics by examples

Filed under: Uncategorized — at 11:10 pm on Monday, October 8, 2007

In this post I will show you some of the PowerShell basic features by examples.

Variables

Variable Declaration

$var = “hello”

Typed Variables

[int]$int_var = 5

Output a variable

$var

or

Write-Host $var

Reading from the console

$var = Read-Host “Write a value”

Array Variables

Init an array variable

$array = 1,2,3

Get an array value

$var = $array[1]

Functions

Sample function

function multiply([int]$a, [int]$b)
{
  return $a + $b
}

Objects (COM or .NET)

Creating a .NET object

$dotNet_DateTime = New-Object -Type System.DateTime 2006,12,25

Creating a COM object

$com_InternetExplorer = new-object –comobject InternetExplorer.application

Logic Statements

Do While

$i = 1
Do{$a; $a++ }
While ($a -lt 5)

Do Until

$i = 1
Do{$a; $a++ }
Until ($a -lt 5)

For

for($i = 1; $i -lt 5; $i++){$a}

ForEach

Foreach ($obj in get-service){ $obj.Name}

IF

$var = “big”
if ($var -eq “small”)
{”Var is Small”}
elseif($var -eq “big”)
{”Var is Big”}
else
{”Var is Medium”}

SWITCH

$var = “big”
switch ($var)

   “big”         {”Var is Big”}
   “small”     {”Var is Small”}
   default     {”Var is Medium”}
}

Files

Reading a text file

$arch = Get-Content “some_file.txt”

Writing…

…to a text file

$text | out-file file_name.txt

…to an HTML file

$text | Convertto-Html > file_name.html

…to a CSV file

$text | Export-Csv file_name.csv

Scripts Files

Passing Command Line Arguments to a script file

.\myPS arg1 arg2

Reading Command Line Arguments from the script file

$readsomething = $args[0]

Samples

Reading a RSS feed

([xml](new-object net.webclient).DownloadString( “http://staff.southworks.net/blogs/MainFeed.aspx”)).rss.channel.item | format-table creator,title,link

Getting the current Wallpaper using WMI

get-wmiobject -class win32_desktop | select-object -property Wallpaper

Loading a .NET WinForm window

[void][reflection.assembly]::LoadWithPartialName(”System.Windows.Forms”)
$form = new-object Windows.Forms.Form
$form.Text = “A WinForms loaded by PowerShell”
$button = new-object Windows.Forms.Button
$button.text=”Click on me!”
$button.Dock=”fill”
$button.add_click({$form.close()})
$form.controls.add($button)
$form.Add_Shown({$form.Activate()})
$form.ShowDialog()

Opening Internet Explorer browser using COM

$ie = new-object –comobject InternetExplorer.application
$ie.Visible = $True
$ie.Navigate(”http://www.southworks.net”)

I hope this helps!

Opening Solution files created using Visual Studio Orcas in Visual Studio 2008 Beta 2 with "double click" :)

Filed under: VisualStudio — at 5:39 pm on Thursday, September 27, 2007

If you have installed Visual Studio 2008 Beta 2, you may have noticed that the solutions you have created using Visual Studio Orcas do not open with a simple “double click” in the Visual Studio 2008 Beta 2 IDE.

A simple way to solve this little issue is opening the solution file (the .sln file) with a text editor and replace its second line in the following way:

Change this:

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio Codename Orcas

to this:

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008

Now you will be able to open the solutions double clicking in the solution file :)

I hope this helps!

Deployment issue when making a Smart Device Application

Filed under: PowerShell — at 1:42 am on Saturday, September 22, 2007

I was developing a Smart Device Application with Visual Studio 2008 Beta 2 (VS). I was following a TDD approach, so I created a Smart Device Class Library project, added some methods in my logic class and created a Unit Test project.

I added some test logic and then I run all test in solution, but I receive the following exception message:

The test adapter (’Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’) required to execute this test could not be loaded. Check that the test adapter is installed properly. Exception of type ‘Microsoft.VisualStudio.SmartDevice.TestHostAdapter.DeviceAgent.NetCFNotInstalledException’ was thrown.

I have asked the Microsoft Mobile Team about that and they have told me that the above exception is because the .NET Compact Framework 3.5 is not deployed on the device emulator when running unit tests when the solution is composed of a class library and a test project.

So, following the suggestions of the Microsoft Mobile Team, I have solved it in two deferent ways and I will tell you how:

A workaround way:

Add to the solution a Device Application Project, so this way, the .NET CF 3.5 is deployed into the device emulator. Then I run the Device Application, so VS prompt you to select an emulator to deploy into, select one to run the application. After that, run the test from VS. As the Microsoft Mobile Team suggests in this post: http://blogs.msdn.com/amit_chopra/archive/2007/09/20/why-do-i-get-this-exception-when-running-a-unit-test-for-devices-on-visual-studio-2008-beta-2.aspx

A cleaner way:

I have installed .NET CF into the emulator device image.

So, to do this:

Add the following folder to act as a Storage Card in the emulator device, to do so:

  1. Open the Device Emulator Manager from Tools -> Device Emulator Manager.
  2. Right click on your emulator, and select Connect, this open the device emulator window.
  3. From the Device Emulator Window, select File -> Configure.
  4. In the General Tab add the following shared folder so its contents appears as a Storage Card in the emulator device.

C:\Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE

In the emulator device, select the File Explorer, and then the Storage card. You should see several files, click the NETCFv35.wm.armv4i.cab file to install the .NET Compact Framework into the emulator device.

The .NET CF gets installed and after a restart, you should be able to run the unit test.

I hope this helps!

Adrián.

How the DataPager control works on Visual Studio 2008 Beta 2

Filed under: controls datapager — at 1:49 am on Friday, September 7, 2007
In this post

Introduction
Which controls could be paged with the DataPager control
How to configure how many items to display per page
How to add/configure page numbers and first/last buttons
Sample Application

Introduction

The DataPager is a simple control that allows you to show result from another control in several groups of pages.

DataPager control output example

How it works

You should indicate in the PagedControlId property of the DataPager the Id of the control that you want to paginate and it is obligatory or a “No IPagableItemContainer was found exception” is thrown at run-time; but, not every control id can be used.

Which controls could be paged with the DataPager control

The paged control should implement IPagableItemContainer interface and at this time just the ListView control implements that interface.

How to configure how many items to display per page

You also set the maximum number of items to display per page with the PageSize property, its default value is 10.

How to add/configure page numbers and first/last buttons

You may do this with the Edit Pager Fields option of the SmartTag in Design View. To do so, right-click on the DataPager control and choose Show Smart Tag. From the SmartTag select Edit Pager Fields.

The following window appears:

From the Available fields text area you may select the following:

  • Numeric Pager Field: which has the configuration for the page numbers and previous and next buttons.
    • The ButtonCount property indicates how many button numbers to display
    • You have some properties to apply CSS styles, you may check this post.
  • Next/Previous Pager Fields: which has previous and next buttons again, but also has First and Last buttons to navigate to the begin or end of the item-list if you have to paginate lots of items.
  • Template Pager Fields: if you need to add custom behavior.

From the Selected Fields text area, you may set the order in which they will be rendered using the up and down arrows.

Sample Application

I have made a sample web application which you can download here that uses the following controls

  • DataPager
  • ListView
  • XML Data Source

Note: You require to have Visual Studio 2008 Beta 2 installed to run the sample.

ScreenShot from the Sample Application

I hope this helps!

Applying CSS styles to the DataPager Control in Visual Studio 2008 Beta 2

Filed under: controls datapager — at 10:12 pm on Thursday, September 6, 2007

Introduction

In this post I will show a way to apply CSS styles to the DataPager control in Visual Studio 2008 Beta2.

This post has the following sections:

  • Context Explains the problem context
  • Solution Shows a way of applying a style to the DataPager control
  • Attachment Comments the sample application that you may download
  • Summary

Context

If you are working on Source View in Visual Studio 2008 Beta 2 and drag a DataPager Control, you will notice that the Properties window neither shows information about CSS styles nor contains information about the DataPager Fields. This also happens in Design View if you choose no style from the SmartTag.

In most examples of what I have seen, the style on the DataPager control is applied by surrounding it with a <div> element and assigning styles to the html elements inside the div generated by the DataPager control, but breaking the DataPager control encapsulation, as the styles are applied on the DataPager generated html elements.

The DataPager control does not have any CSSClass property because it inherits from System.Web.UI.Control (not from System.Web.UI.WebControls.WebControl).

Solution

You should add the style to the DataPager Fields. To do so, go to Design View and open the SmartTag right -clicking over the DataPager control and choosing Show Smart Tag; and select Edit Pager Fields. The following window appears:

In this screenshot a Numeric Pager Field is selected, and in the right panel the following properties can be configured:

  • CurrentPageLabelCssClass: is the style applied to the current page number which has no link.
  • NumericButtonCssClass: is the style that affects the other page numbers which have a link.
  • NextPreviousButtonCssClass: is the style applied to the previous/next button and have a link.

You still have to surround the DataPager control with a

element if you want to center it; and apply to that div a “text-align:centerCSS property.

Attachment

Download the Sample web application here.

I have attached a simple sample web application which makes use of the following controls:

  • DataPager
  • ListView
  • XML Data Source

Summary

You have seen a way of applying CSS styles to the DataPager control in Visual Studio 2008 Beta 2.

I want to thank Paulo Arancibia for the board pictures and to Southworks team for encourage and help me to make headway.