XBOX 360 friends status APP

After seeing a great XBOX360 friends Iphone App I decided to build a Windows Mobile version of it. The app shows your friends, their avatar, online status and what they are playing. After downloading the VS plugins for Windows Mobile development I started building the app. Building Windows Mobile Apps is easy. The only thing you need to know is that you can never build a application which have the same user experience and GUI as a Iphone. Maybe Windows Mobile 7 and XAML will fix this.

Here is result of one night programming. Clearly it is not finished but it`s a fun app. The application features are:

  • friend overview, see status of your friends
  • settings page, where you can set the polling time
  • An exit button, to clear te memory.
  • It even gives an alert when a friend comes online.

What I would like to add:

  • XML for your friendlist (it is hard coded now)

Here are some screenshots of the application.

And you can download the sourcecode here.

C#: Get Parent Control with Generics

I use the following method to return a parent control of a specific type. This method is recursive and uses generics.

<br />
private Control GetParentControl(Control control)<br />
{<br />
if (control.Parent.GetType() == typeof(T1))<br />
{<br />
return control.Parent;<br />
}<br />
else<br />
{<br />
return GetParentControl(control.Parent);<br />
}<br />
}</p>
<p>

MemoryStream to Byte Array (Byte[])

With the following code you can convert your MemoryStream to a Byte Array.


//create new Bite Array
byte[] biteArray = new byte[memoryStream.Length];

//Set pointer to the beginning of the stream
memoryStream.Position = 0;

//Read the entire stream
memoryStream.Read(biteArray, 0, (int)memoryStream.Length);

Gaatverweg.nl travelportal live

A few years after building the free travelblog site Globallog.nl in PHP. I started building a new version in .Net together with Mark. Although this was a joyful and educational experience, we never finished this project… Now a few years later I finished a new travelblog portal; Gaatverweg.nl.

Gaatverweg.nl is build with WordPress MU (php) and uses multiple WordPress plugins and a few custom build plugins.

Create a Visual Studio add-in with contextmenu and selected text as input

Create a Visual Studio add-in with contextmenu and selected text as input

When working with a new way of storing settings in a database. I was frustrated how much work it was to check the value of setting from code. So I deceided to make my life a bit easier by creating a VS2008 contextmenu add-in. With this add-in I can select text within VS and use the value of the selected text within the add-in popup. The hardest part was figuring out how to create a contextmenu and how to use the selected text as input value.

In this blogpost I will show how to create a Visual Studio contextmenu add-in and pass the selected text to the pop-up. I’m not going to explain how to create an add-in you can easily find articles about this on MSDN or blogs (just try Google).

Now let’s get started. Create an new Visual Studio add-in project and add the following code to the OnConnetion Method within the Connect.cs. This code will insert add the contextmenu.


_applicationObject = (DTE2)application;
CommandBars cBars = (CommandBars)_applicationObject.CommandBars;

CommandBar editorCommandBar = (CommandBar)cBars["Editor Context Menus"];
CommandBarPopup editPopUp = (CommandBarPopup)editorCommandBar.Controls["Code Window"];

Command command = commands.AddNamedCommand2(_addInInstance,
 "GetSetting", "Bekijk Setting", "Executes the command for test", true, 733, ref contextGUIDS,
 (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
 (int)vsCommandStyle.vsCommandStylePictAndText,
 vsCommandControlType.vsCommandControlTypeButton);

Then to get the selected text I use the following method within the Exec of the Connect.cs and pass the selected text (return value) to a property of a Windows Form pop-up.


private string GetSelection()
{
    string setting = "";

    //Check active document
    if (_applicationObject.ActiveDocument != null)
    {
        //Get active document
        TextDocument objTextDocument = (TextDocument)_applicationObject.ActiveDocument.Object("");
        TextSelection objTextSelection = objTextDocument.Selection;

        if (!String.IsNullOrEmpty(objTextSelection.Text))
        {
 //Get selected text
            setting = objTextSelection.Text;
        }
    }
    return setting;
}

Hope it helps.

Cheers,
Pieter

C#: Remove line from textfile

With the following code you can remove a line from a textfile (web.config). If the string is within a line the line will be removed.


string configFile = @"C:devweb.config";
List lineList = File.ReadAllLines(configFile).ToList();
lineList = lineList.Where(x =&gt; x.IndexOf("&lt;!--&quot;) &lt;= 0).ToList();
File.WriteAllLines(configFile, lineList.ToArray());


Asp.Net: DataPager problem with Listview

When using the Datapager with a ListView I had the following problem. When clicking a paging button for the first time nothing happens.But when I click a button the second time, then the page from the first click loads.

I search the internet for a solution and found that you need to add some code to the OnPagePropertiesChanging event of the list view to reload the DataPager.

The following code is the solution to my problem. Including a fix that the data doesn’t get loaded two times.


private List productList;

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
        fillGrid();
}

private void fillGrid()
{
    if(productList == null)
        productList = getproducts();
    ListView1.DataSource = productList;
    ListView1.DataBind();
    DataPager1.DataBind();
}

public List getproducts()
{
    using (AdventureWrksDataContext db = new AdventureWrksDataContext())
    {
        return db.Products.ToList();
    }
}

protected void lvproducts_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
    DataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
    fillGrid();
}


You can download the solution (PagingExample.zip (83.05 kb))

Cheers,

Pieter