Bind a list of Folders to a DataGrid

The following example demonstrates using aspNetIMAP, in an ASP.NET page, to bind a list of folders to a DataGrid.

[C#]

IMAP4 imap = new IMAP4( "127.0.0.1" );
 
imap.Username = "dave@blah.com";
imap.Password = "test";
imap.Login();
 
//list all of the folders
MailFolderCollection mfc = imap.FolderList();
 
imap.Disconnect();
 
//bind the MailFolderCollection to a DataGrid
DataGrid dg = new DataGrid();
dg.DataSource = mfc.ToDataSet();
dg.DataBind();
 
Page.Controls.Add( dg );

 

[VB.NET]

Dim imap As New IMAP4("127.0.0.1")
 
imap.Username = "dave@blah.com"
imap.Password = "test"
imap.Login()
 
'list all of the folders
Dim mfc As MailFolderCollection = imap.FolderList()
 
imap.Disconnect()
 
'bind the MailFolderCollection to a DataGrid
Dim dg As New DataGrid()
dg.DataSource = mfc.ToDataSet()
dg.DataBind()
 
Page.Controls.Add(dg)