Article ID: 152316
Article Last Modified on 11/21/2006
119591 How to Obtain Microsoft Support Files from Online Services
// Command handler which performs the pertinent operations
/////////////////////////////////////////////////////////////////////
//
void CCONDOCView::OnGetinfoOpenMDB()
{
// Prepare the open file dialog
static char BASED_CODE szFilter[] = _
T( "Access Database Files (*.mdb) | *.mdb" );
CFileDialog dlg(TRUE, "mdb", NULL,
OFN_HIDEREADONLY| OFN_OVERWRITEPROMPT, szFilter);
// To be retrieved by the open file dialog
CString strFile;
// open file dialog
if(dlg.DoModal() == IDOK)
{
strFile = dlg.m_ofn.lpstrFile;
if(strFile.Right(3).CompareNoCase("mdb") // verify extension
{
AfxMessageBox("File Extension error");
return;
}
}
// you will display the info in a tree control
CTreeCtrl &tree = GetTreeCtrl();
// the root of all items!
HTREEITEM itemDatabase = tree.InsertItem(
dlg.m_ofn.lpstrFile );
// An MFC DAO object
CDaoDatabase db;
// straight DAO interface pointer variables
ConDoctainers *pContainers=NULL;
ConDoctainer* pCon=NULL;
DAODocuments* pDocuments=NULL;
DAODocument* pDoc=NULL;
// To be used for iterating through the collections
short count;
short doccount;
// open the .MDB
try
{
db.Open( strFile );
}
catch( CDaoException* e )
{
AfxMessageBox( e->m_pErrorInfo->m_strDescription );
return;
}
// Using the DAODatabase interface pointer method contained
// by the MFC/DAO class CDaoDatabase, you retrieve the interface's
// set of collections.
if( FAILED( db.m_pDAODatabase->get_Containers( &pContainers ) ) )
{
AfxMessageBox( "Collection not found" );
db.Close();
return;
}
// Once you have the set of collections, you iterate thru each
// individual collection, display some of its attributes,
// then get the document collection on the container,
// and iterate thru the individual documents, displaying some
// of the attributes of the documents.
// See the dbdao.h in the DAOSDK\INCLUDE for more information
try
{
// get the count property of the containers collection
pContainers->get_Count( &count );
HTREEITEM itemContainers = tree.InsertItem( _T( "Containers" )
, itemDatabase );
// iterate thru the containers
while( --count > 0 )
{
// get an individual container and iterate thru its
//attributes
pContainers->get_Item( COleVariant( count, VT_I2 ),
&pCon );
BSTR bstr=NULL;
pCon->get_Name( &bstr );
CString strName( ( LPCTSTR ) bstr );
HTREEITEM itemName = tree.InsertItem( strName,
itemContainers );
pCon->get_Owner( &bstr );
CString strOwner(_T("Owner: ") );
strOwner += (LPCTSTR) bstr;
HTREEITEM itemOwner = tree.InsertItem( strOwner,
itemName );
pCon->get_UserName( &bstr );
CString strUserName(_T("User Name: ") );
strUserName += (LPCTSTR) bstr;
HTREEITEM itemUserName = tree.InsertItem( strUserName,
itemName );
// Now get the documents collection
if( FAILED ( pCon->get_Documents( &pDocuments ) ) )
{
AfxMessageBox( "Collection not found" );
db.Close();
return;
}
// Now get the number of documents contained in the
// container
pDocuments->get_Count( &doccount );
HTREEITEM itemDocuments = tree.InsertItem(
_T( "Documents"), itemName );
// iterate thru the documents
while( --doccount > 0 )
{
// get an individual document and iterate thru
// some of its attributes.
pDocuments->get_Item( COleVariant( doccount, VT_I2 ),
&pDoc );
pDoc->get_Name( &bstr );
CString strDocName( ( LPCTSTR ) bstr );
HTREEITEM itemDocName = tree.InsertItem( strDocName,
itemDocuments );
pDoc->get_Owner( &bstr );
CString strDocOwner(_T("Owner: ") );
strDocOwner += (LPCTSTR) bstr;
tree.InsertItem( strDocOwner, itemDocName );
pCon->get_UserName( &bstr );
CString strDocUserName(_T("User Name: ") );
strDocUserName += (LPCTSTR) bstr;
tree.InsertItem( strDocUserName, itemDocName );
}
}
}
catch( CDaoException* e)
{
AfxMessageBox( e->m_pErrorInfo->m_strDescription );
db.Close();
return;
}
db.Close();
}
/////////////////////////////////////////////////////////////////////
// END OF SAMPLE CODE
Additional query words: 4.00 4.10 4.20 prop
Keywords: kbdownload kbcode kbdatabase kbfile kbsample KB152316