Exporting a public key using PowerShell

Example:

$certs = Get-ChildItem Cert:\LocalMachine\My
$type = [System.Security.Cryptography.X509Certificates.X509ContentType]::Cert
# Pick the first cert
$certBytes = $certs[0].Export($type)
[System.IO.File]::WriteAllBytes("nnn.cer", $certBytes)
Advertisements

Syncing Internet Explorer favorites using SkyDrive

I think I finally found a way to sync Internet Explorer favorites using SkyDrive. As you probably know, you can only sync one local folder (normally C:\Users\<user name>\SkyDrive). But using symbolic links, you can in fact “cheat” to make Internet Explorer use the SkyDrive folder.

First, I created a folder named Favorites in SkyDrive. Then, I started an elevated command prompt (“run as administrator”) and ran this command on each computer:

cd C:\Users\<user name>
ren Favorites Favorites.bak
mklink /d Favorites C:\Users\<user name>\SkyDrive\Favorites

That’s it!

Edit: There is a much simpler method. Select the Favorites folder in file Explorer, then select properties, then go to the location tab, then type C:\Users\<user name>\SkyDrive\Favorites as the new location and click the Move button.

Cannot get the BizTalk ExposeWebService sample to run on Windows XP

I had problems getting the BizTalk 2006 R2 ExposeWebService sample to run on my Windows XP machine. The published orchestration threw a SOAPException. The event log said

 

An attempt to connect to "BizTalkMgmtDb" SQL Server database on server "SE-890652" failed. Error: "Cannot open database "BizTalkMgmtDb" requested by the login. The login failed."

 

and

 

The Messaging Engine failed to register the adapter for "SOAP" for the receive location "/ExposeWebService_Proxy/Microsoft_Samples_BizTalk_ExposeWebService_ProcessClientRequest_SOAPPort.asmx". Please verify that the receive location exists, and that the isolated adapter runs under an account that has access to the BizTalk databases.

 

Clear as a cucumber. You need to add the account that the isolated adapter runs under to the BizTalk Isolated Host Users group. But which account? In Windows Server 2003 (IIS 6), you can configure the account the application pool is using, as pointed out in the documentation (ms-help://MS.BTS.2006/BTS06CoreDocs/html/b6d2377b-5a8c-4f1c-8d01-75d3f34bef6a.htm). But Windows XP (IIS 5) does not have this feature. It turns out it is the local ASPNET account that has to be added to the BizTalk Isolated Host Users group. Run IISReset before trying again. 

Binding a DataGrid in .Net

I wanted to bind a Windows form datagrid to data source which was a strongly typed (generic) collection and went into problems. So I investigated how to bind to four different datasources: a DataSet, a typed array, an untyped list (ArrayList) and a typed list (generic List). Here’s how to do it. This code also demonstrates how to customize the displayed columns. The records displayed only contains one column called "Title".
 

private void DisplayDataSet()

{

    dataSet1.Tables[0].Rows.Add("Title 1");

    dataSet1.Tables[0].Rows.Add("Title 2");

    DataGridTableStyle tableStyle = new DataGridTableStyle();

    tableStyle.MappingName = "Titles";

    DataGridColumnStyle columnStyle = new DataGridTextBoxColumn();

    columnStyle.MappingName = "Title";

    columnStyle.HeaderText = "Title";

    columnStyle.Width = dataGrid1.Width;

    tableStyle.GridColumnStyles.Add(columnStyle);

    dataGrid1.TableStyles.Add(tableStyle);

    dataGrid1.DataSource = dataSet1;

    dataGrid1.DataMember = "Titles";

}

 

private void DisplayTypedArray()

{

    Record[] titles = new Record[2];

    titles[0] = new Record("Title 3");

    titles[1] = new Record("Title 4");

    DataGridTableStyle tableStyle = new DataGridTableStyle();

    tableStyle.MappingName = "Record[]";

    DataGridColumnStyle columnStyle = new DataGridTextBoxColumn();

    columnStyle.MappingName = "Title";

    columnStyle.HeaderText = "Title";

    columnStyle.Width = dataGrid2.Width;

    tableStyle.GridColumnStyles.Add(columnStyle);

    dataGrid2.TableStyles.Add(tableStyle);

    dataGrid2.DataSource = titles;

}

 

private void DisplayArrayList()

{

    System.Collections.ArrayList titles = new System.Collections.ArrayList();

    titles.Add(new Record("Title 5"));

    titles.Add(new Record("Title 6"));

    DataGridTableStyle tableStyle = new DataGridTableStyle();

    tableStyle.MappingName = "ArrayList";

    DataGridColumnStyle columnStyle = new DataGridTextBoxColumn();

    columnStyle.MappingName = "Title";

    columnStyle.HeaderText = "Title";

    columnStyle.Width = dataGrid3.Width;

    tableStyle.GridColumnStyles.Add(columnStyle);

    dataGrid3.TableStyles.Add(tableStyle);

    dataGrid3.DataSource = titles;

}

 

private void DisplayTypedList()

{

    System.Collections.Generic.List<Record> titles = new System.Collections.Generic.List<Record>();

    titles.Add(new Record("Title 7"));

    titles.Add(new Record("Title 8"));

    DataGridTableStyle tableStyle = new DataGridTableStyle();

    tableStyle.MappingName = titles.GetType().Name;

    DataGridColumnStyle columnStyle = new DataGridTextBoxColumn();

    columnStyle.MappingName = "Title";

    columnStyle.HeaderText = "Title";

    columnStyle.Width = dataGrid4.Width;

    tableStyle.GridColumnStyles.Add(columnStyle);

    dataGrid4.TableStyles.Add(tableStyle);

    dataGrid4.DataSource = titles;

}

 

public class Record

{

    private string title;

    public string Title

    {

        get { return title; }

        set { title = value; }

    }

   

    public Record(string title)

    {

        this.title = title;

    }

}