Visual Studio Default Key binding posters

Posted April 26th, 2010 in .NET, Visual Studio by Sam Beauvois

The visual studio 2010 keybinding poster is available since a few weeks.

Visual C# 2010 default key bindings preview :

VS2010CsharpKeyBinding1

VS2010CsharpKeyBinding2

Shortcuts are grouped by category (debuging, refactoring, editing, navigation, …)

Here is the Visual Studio Keyboard shortcuts posters for C#:

Visual Studio 2010

Visual Studio  2008

Visual Studio 2005

Enjoy them !

Custom paging with Subsonic 3 and ObjectDataSource in ASP.NET

Posted April 22nd, 2010 in .NET, ASP.NET, SubSonic by Sam Beauvois

Here is how I created a paged items list in ASP.NET 3.5 using Subsonic for data access, and ASP.NET Controls for the display.

I use Subsonic 3.0.0.4 with ActiveRecord and ASP.NET 3.5 SP1 webforms.

For this example, we are creating a blog post list and that the DAL is created (the data class we use is “DAL.BlogPost”).

The DAL.BlogPost object has three properties we need : CreatedOn, Subject and Body.

First step : prepare your data manager class


namespace MyBlog.BLL
{
   public class PostManager
   {
     // ...
   }
}

(keep in mind the namespace and the class for the nexts steps)

In this class, two methods are required,

The first returns the total number of items


public int GetPostCount()
{
  return DAL.BlogPost.All().Count(x => x.IsDeleted != true);
}

The second one returns the items contained in a defined range (start index and then nomber of elements), so this method needs to know where to start and how many items to get.


public PagedList<DAL.BlogPost> GetLastestPosts(int startRowIndex, int maximumRows)
{
   if (startRowIndex != 0)
   {
     startRowIndex =(startRowIndex/maximumRows);
   }

    IOrderedQueryable<DAL.BlogPost> yourQuery = DAL.BlogPost.All().OrderByDescending(x => x.CreatedOn);
    return new PagedList<DAL.BlogPost>(yourQuery, startRowIndex, maximumRows);
}

One important part to remember when using Subsonic is


if (startRowIndex != 0)
{
   startRowIndex = startRowIndex / maximumRows;
}

This conversion is necessary because subsonic and the ObjectDataSource doesn’t share the same opinion about the paging method.
Subsonic says

“I want the third page containing five elements”

ObjectDataSource says

“I want the five elements following the third element”

So the conversion is mandatory if you want a correct paging.

Second step : create the aspx page.

Declare an ObjectDataSource:

<asp:ObjectDataSource runat="server" ID="postsDataSource"
 TypeName="Example.BLL.PostManager"
 SelectMethod="GetLastestPosts"
 EnablePaging="true"
 SelectCountMethod="GetPostCount" >
 </asp:ObjectDataSource>

Note the TypeName attribute : the value is the namespace + the class name of our datamanager class.
We set the EnablePaging attribute to true and we specify the SelectCountMethod and the SelectMethod.

We don’t need any parameters for the paging, by default the MaximumRowsParameterName and StartRowIndexParameterName are set to “maximumRows” and “startRowIndex”.
If we want other parameters names in our datamanager class, we can define them in the ObjectDataSource with these two parameters.

Add an asp ListView element

<asp:ListView runat="server" ID="postsListview"
     DataSourceID="postsDataSource">
 <LayoutTemplate>
    <asp:PlaceHolder ID="itemPlaceHolder"
         runat="server" />
 </LayoutTemplate>
 <ItemTemplate>
    <h2><%# Eval("CreatedOn","{0:d}")%> :
     <%# Eval("Subject") %></h2>
    <br />
    <p>
     <%# Eval("Body") %>
    </p>
    <hr />
 </ItemTemplate>
</asp:ListView>

Set the DataSourceID attribute to the ObjectDataSource ID parameter.

Define a LayoutTemplate and an ItemTemplate with the elements we want to display.

Then add an asp datapager control in the LayoutTemplate


<LayoutTemplate>

  <asp:DataPager ID="postsDataPager" runat="server"
       PageSize="3">
    <Fields>
      <asp:NextPreviousPagerField ButtonType="Link"
           FirstPageText="<<" PreviousPageText="<"
           ShowNextPageButton="false"
           ShowFirstPageButton="true" />
      <asp:NumericPagerField PreviousPageText="..."
           NextPageText="..." ButtonCount="10" />
      <asp:NextPreviousPagerField ButtonType="Link"
           LastPageText=">>" NextPageText=">"
           ShowPreviousPageButton="false"
           ShowLastPageButton="true" />
     </Fields>
   </asp:DataPager>

   <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
 </LayoutTemplate>

Here is the result :
blogposts

Remark about the data access method

It’s possible to avoid the start index value conversion !

Check the PagedList first constructor code (code is available on the subsonic git repository)


public PagedList(IQueryable<T> source, int index, int pageSize)
{
   int total = source.Count();
   TotalCount = total;
   TotalPages = total / pageSize;

   if(total % pageSize > 0)
     TotalPages++;

   PageSize = pageSize;
   PageIndex = index;
   AddRange(source.Skip(index * pageSize).Take(pageSize).ToList());
}

As you can see, Subsonic use the Skip and the Take methods from Linq

So, you can modify the GetLastestPosts method to return a strongly typed List in place of the PagedList:


public List<DAL.BlogPost> GetLastestPosts(int startRowIndex, int maximumRows)
{
   return DAL.BlogPost.All().
          Skip(startRowIndex).
          Take(maximumRows).
          OrderByDescending(x => x.CreatedOn).
          ToList<DAL.BlogPost>();
}

With this method, no more conversion needed

First use of Visual Studio 2010 : the installation

Posted April 16th, 2010 in .NET, Tools, Visual Studio by Sam Beauvois

Yesterday I received a visual studio 2010 Ultimate edition from work.

I’ve already test the  express edition when it was in beta phase, but it’s not the same …

So, let’s install it !

I install it on a Fujitsu Siemens laptop with 4 GB Ram and a Intel Core 2 Duo processor (2,53 GHz) running  Windows 7 64 bit Ultimate edition.

image

 

Launch the auto run program

image

Loading screen

image

Click Next

image

Read and accept the license terms

image

Choose your installation mode : Full installation (takes more than 6 GB) or Custom installation

image

I choose Custom

image

Select the features you want :

image

(notice that “Microsoft SharePoint Developer Tools” are integrated)

I just don’t want Dotfuscator community to be installed, so I uncheck  it

I keep the rest because I want to test some features

image

Click Install

Installation running :

image

After less than 10 minutes, the installation asked me to restart my computer:

image

image

I click “Restart Now”

 

When restarting, a loading form is showing

image

Then the setup continue

image

After about 45 minutes, the setup is finished

image

You can choose to install the documentation, but I choose to click on the “Finish” button.

 

The installation windows appears :

image

I Click Exit

Visual Studio 2010 is now installed

 

The installation takes me about one hour, and no problem occurred.

Now I can launch the product

image

 

image

 

I choose my default environment settings (I used to choose Visual C# Development settings so I pick this one).

image

I Click on “Start Visual Studio”

First time loading form

image

 

Visual studio is up and running

image

 

Help and documentation are on the start page:

A What’s new section is available on the start page :

Some other links are available :

  • Creating application with Visual Studio
  • Extending Visual Studio
  • Community and Learning Resources

 

Some resources for Windows, Web, Cloud, Office,SharePoint and Data development are accessible too.

 

Next step : migration of a Visual studio 2008 solution !

CSS Mixer

Posted February 25th, 2010 in .NET, ASP.NET, CSS, MyProjects, Personal, Tools, Web development by admin

CSSmixer128 Css mixer is a tool I’ve developped in C# winforms, .NET framework 3.5

You can use it to improve you ASP.NET Themes or your CSS files for all your web projects.

If you have many css files linked to a page, you can group them in a single file with CSS Mixer.

You can also minify CSS files to save the bandwith.

 

To use it, open a folder containing CSS files,

cssmixer_screenshot

choose an action (simple combine, or combine and minify) then click Save as …

cssmixer_screenshot2

Download the last version of CSS Mixer on codeplex.

I hope you’ll find it usefull. please give me feedback on it

Copy datatable’s row to an other datatable’s row

Posted January 16th, 2010 in .NET by Sam Beauvois

This method perform a row copy with a few checks


public static void CopyRowToAnOther(DataRow row, DataRow anOtherRow)
        {

            if (row == null || row.Table == null
                || anOtherRow == null || anOtherRow.Table == null)
            {
                return;
            }

            foreach (DataColumn colunm in row.Table.Columns)
            {
                if (anOtherRow.Table.Columns.Contains(colunm.ColumnName)
                && !row.IsNull(colunm.ColumnName)
                && colunm.DataType == anOtherRow.Table.Columns[colunm.ColumnName].DataType)
                {
                    anOtherRow[colunm.ColumnName] = row[colunm.ColumnName];
                }
            }
        }
public static void CopyRowToAnOther(DataRow row, DataRow anOtherRow)

{

if (row == null || row.Table == null || anOtherRow == null || anOtherRow.Table==null)

{

return;

}

foreach (DataColumn colunm in row.Table.Columns)

{

if (anOtherRow.Table.Columns.Contains(colunm.ColumnName)

&& !row.IsNull(colunm.ColumnName)

&& colunm.DataType == anOtherRow.Table.Columns[colunm.ColumnName].DataType)

{

anOtherRow[colunm.ColumnName] = row[colunm.ColumnName];

}

}

}