Archive for the 'Programming' Category

3rd MS Kapihan

What supposed to be a Saturday event turned out as a holiday event. With the President declared Tuesday as a national holiday, the MVPs who met last Wednesday finalized the next MS Kapihan session will be held on the holiday and this time in Subic. This is my second kapihan session as I missed the first one since I have a class back then in UP and we were so delayed in schedule that I cannot afford to skip another Saturday. Everyone who joined came in at SM North Edsa yesterday to join a van convoy going to Subic. With members of the community as well as some Microsoft Student Partners, we embarked a 2+ hours travel to Subic via SCTEX. This is my second time to pass by SCTEX and unfortunately, I witnessed another accident along the road.

The topics discussed in this kapihan session revolved around the Microsoft Azure Platform. This is one of the topics I am particularly interested in aside from the topic covered during the second MS Kapihan that revolved around Windows Phone 7. The discussion kicked-off by myself, discussing the free add-on for Visual Studio 2010 that makes development much more transparent and easier to track methods in one of the features that it have – the Productivity Power Tools for Visual Studio 2010.

As someone who is more into coding, I find this tool helpful especially the Solution Navigation which I think is the feature that benefit me most. Locating the definitions for the methods I use, properties within the class, the classes where they are defined, parameters and return value are made easy using this one. The window docks itself in the same location where Solution Explorer is located. There’s also a search bar that loops  through the files associated with the currently loaded project/solution.

After the discussion on the tools, it was followed through by MVPs Allan Mangune and John Delizo covering some tools on testing included in the Ultimate SKU of Visual Studio 2010 as well as working with continuous integration with Visual Studio 2010 Team Foundation Server. One of the community members, Joey de Jesus, also discussed the database tools included in the same SKU of Visual Studio.

The main topic on Azure was started by MVP Roman Canlas focusing on the fundamentals of the Azure Platform, components in a nutshell and a brief discussion on the Storage Services. There’s a discussion among the developers and with my delight, the MSPs also participated in the discussion based from their own experience. Honestly, this one is an interesting technology on my part considering that most major players in the IT field are leveraging time, resources, and investments on this type of platform. Aside from Microsoft, other players are Amazon, Google, and IBM to name a few have their own distinct implementations that caters to different cloud computing needs. As for my part, it would be more logical for me to work on the Microsoft platform as most of my development experience leans more on this. After the discussion, lunch was served, and as people who doesn’t love technology but also doing fun, we had another set of photo shooting within the freeport premises and the kulitan by the main building.

This kapihan brought back some of the familiar faces in the Microsoft community. Referred to as the “chief”, Jerome Punzalan, the first president of the Philippine .NET Users group was there to participate and give his insights on the discussion. Also, there are some members as well from Philippine Windows Users Group were there to listen and have their opinions aired. Participation in MS Kapihan is free and I think the next venue would be in Quezon City.

Suggestions? 🙂


ASP.NET Membership Database Migration Helper

This is my project born out of a problem on how to backup the existing data that I have on a website. In one of my projects, I have created a user registration system based on ASP.NET Membership although as I reach the peak of the limits of the database hosting, I need a means to transfer the data from that database to another.

Unfortunately, the original database host of my old project didn’t allow me to connect to the database via SQL Server Management Studio and it would be a pain to manually gather the membership information and maintain its integrity particularly the password if the Membership provider configuration for the password is set to “Hashed”.

I tried searching if there’s an API for programaticaly migrating data but I haven’t found one. Solutions found over the net include backing up the database and restore it in a local store but I find that tedious. I need something that is as much as possible with less clicks. With that, this application is an attempt to solve that problem.


1. Start with Start.aspx (Default.aspx will eventually redirect you to that page). Provide the following information:

a) Source Database Connection String
b) Source Database Application Name
c) Target Database Connection String
d) Target Database Application Name

a & c are obvious reasons why you need to provide them. “b” is needed since we need to specify what specific application database are we backing up. Typically, the ASPNETDB.mdf file that is being created whenever we fire up the Website Administration Tool (WSAT) can handle users for use with Membership for different web applications by virtue of applicationId. This can be verified by opening the aspnet_Applications table. On the other hand “c” is needed since we need to check that the database doesn’t contain that application name as it might overwrite any existing data in there (in cases you want to merge Membership databases).

2. Clicking validate will validate the information that you have provided. Until such time all entries appear to be valid, then it would only be at that period you can click on the “Export >>” button that will perform the actual migration. Likewise, once validated, you can also delete or clear the target database of all it’s entries.


Be aware only that this action is irreversible and there’s no way of backing it up unless you have a spare copy of that database somewhere else.

3. You would be informed in Result.aspx if the migration is okay or not. TryExport.aspx is actually the page that I made to test if the export is working or not. Before trying it out, do the following:

  • Modify web.config by editing the connection string list and the provider list. Edit the connection string section first as the providers will depend on the entries of this section. This application is by default populated with two providers namely: AspNetSqlMembershipProvider (source) and ExportedDBMembershipProvider (destination). The connection string attribute of the provider should match that of the connection string name of the source/destination databases. Failure to do so will prohibit you from validating if the export works or not.
  • The applicationName attribute of the destination provider should match the “Target Application Name” specified in Start.aspx. Failure to do so will prohibit you again from validating if the export works or not.
  • You can change the name of the providers and will allow you to validate however, you need to change as well the values set in the code-behind of TryExport.aspx for the provider name.

Additional Notes:

  • I tested the code to work when transporting between two SQL Server 2005 Express database files. However, the application might throw an error when the data is too big to transfer.
  • This application just exports the application data, membership information and roles. I am still making a way to include the Profile data (if there’s any) to the exported database.

The file is in zip format but since wordpress is not accepting ZIP files as attachment, you can download it here and rename it to .zip.

Comments, reactions, suggestions? Post a comment here!

Building Some Web TreeViews

The TreeView control in ASP.NET 2.0 is used to display hierarchical data, such as table of contents or file directory in a tree structure. In most applications that I do, I use the TreeView control to show file directory structure. I was able to create a class that populates a TreeView provided with a physical directory structure residing on the same computer as to where the server is running. Rename the file below to .dll and use it as a reference on your web application. Once added to your web application usage would be:

using System;
// include other namespaces as needed
using PhysicalTreeView;

public partial class Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        string location;
        pTreeView ptv = new pTreeView(location);
        // the example below is valid without specifying the "isWeb" to false.
        pTreeView ptv = new pTreeView("~/");
        ptv.isWeb = false;

By default, the variable location will treat the path as a virtual path. If you want to specify a specific physical directory, you can specify the 8 character directory format as a location value but you need to specify the property “isWeb” as “false” and as shown above. The “TreeView1” is assumed to be a TreeView control placed onto the ASPX file. For testing purposes, you can put in your code behind the following code without placing a TreeView control in your ASPX file but will output the same.

TreeView TreeView1 = new TreeView();
string location;
pTreeView ptv = new pTreeView(location);
// the example below is valid without specifying the "isWeb" to false.
pTreeView ptv = new pTreeView("~/");
ptv.isWeb = false;


Physical Drive TreeView DLL

The challenge for me is to bring the same functionality to a SourceSafe database which is despite having a directory like structure isn’t directory based at all when accessed programmatically. Furthermore, the DLL provided with Visual Source Safe 2005 isn’t a native .NET object but a COM interop one.

Luckily, using the same logic behind the previous DLL, I managed to create a DLL to populate a TreeView from a SourceSafe database. The constructor needs only 3 parameters namely the database location, username, and password.

Sample usage would be:

using ProjectTreeView;

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

        string location, user, password;
        // Populate your own values

        ssTreeView stv = new ssTreeView(location, user, password);


Same with the code above, the code assumes that there’s a TreeView control instance in the ASPX file that has an ID of “TreeView1”.

Sourcesafe TreeView

For questions, feel free to add some comments. 🙂

Using Hexadecimal Color Values in WPF 3.5

I am currently preparing for my WPF content for the Philippine Launch Wave of Visual Studio 2008, Windows Server 2008, and SQL Server 2008. As a seasoned web developer, I am quite accustomed to the colors that I frequently use in hexadecimal and I intend to use these colors in my demo. I have a basic XAML file that has a Window with a ListBox, TextBlock and Slider in it. I am trying to show how LINQ works in a WPF 3.5 application.

<window x:Class="WpfApplication1.Window1"
    Title="Window1" Height="500" Width="500">
        <listBox Name="listBox1" SelectionChanged="listBox1_SelectionChanged" Margin="0,0,0,120" />
        <textBlock Height="105" Name="textBlock1"  FontSize="{Binding ElementName=slider1, Path=Value}" VerticalAlignment="Bottom">Label</textBlock>
        <slider Height="21" Margin="203,0,-5,0" SizeChanged="slider1_SizeChanged" ValueChanged="slider1_ValueChanged" Minimum="10" Maximum="50" Name="slider1" VerticalAlignment="Bottom" Value="10" />

While working on a certain functionality that I want to display, I became curious if I can use the colors in my sample application. The color, which I don’t exactly know the name but I refer to it as maroonish red (the UP blood in me), has an hexadecimal value of “#cd0001”. I tried appending that value in the Foreground property of the TextBlock (textBlock1 mentioned above) but it doesn’t work.

// This code won't work

textBlock1.Foreground = "#cd0001";

// Even this

textBlock1.Foreground = (Brush)"#cd0001";

To have a workaround on this, you need to use the BrushConverter class in able to use your hexadecimal based colors as a brush.

BrushConverter bc = new BrushConverter();
Brush brush;
brush = (Brush)bc.ConvertFrom("#cd0001");
textBlock1.Foreground = brush;

And it works! If you are more familiar with the colors that you want in hexadecimal, you can replace the hex value in the text above and most likely that would work.


Searching Approved Users in Roles in ASP.NET Membership

Still more ASP.NET membership tweaks!

The role manager in ASP.NET Membership provides a mechanism to list all the users in the ASP.NET Membership Database for a specific role.


This method returns a string array of usernames that’s a member of that role. Unfortunately, this list returns all the users even if they are approved or not, locked out or not. If you are working on an application that requires to filter out users in the role that’s locked out or isn’t approved yet, there’s no other mechanism on the built-in methods. There’s no overload to the method provided out of the box.roles.png

Luckily, as mentioned in the previous blog about ASP.NET membership, the database is filled with various stored procedures that you can use (or even pattern after) for various usage. I tweaked one of the stored procedures and came up with a stored procedure that gets all the approved users in the ASP.NET membership database.

CREATE PROCEDURE dbo.Membership_GetActiveUsersInRoles

    @RoleName nvarchar(256)



        DECLARE @RoleId uniqueidentifier

        SELECT @RoleId = RoleId
        FROM dbo.aspnet_Roles
        WHERE LOWER(@RoleName) = LoweredRoleName

        SELECT u.UserName, u.UserId
        FROM dbo.aspnet_Users u, dbo.aspnet_UsersInRoles ur, dbo.aspnet_Membership m
        u.UserId = m.UserId AND
        u.UserId = ur.UserId AND
        @RoleId = ur.RoleId and
        m.IsApproved = 'true'
         -- You can also specify m.IsLockedOut = 'false' for other purposes


Just copy the said code above and create it in your ASP.NET Membership database (either that ASPNETDB.MDF or an ASP.NET membership configured database) and run it.Happy Coding!

Exploring Ruby

I am currently studying Ruby on Rails. I already got the stuff needed for this before only I had the time exploring more the technology right now.

After PHP, ASP.NET, I’m now checking on Ruby. Hope this one will impress me. 🙂

Blog Stats

  • 4,031 hits
July 2018
« Nov