Here is a little function that will get you through the part I found trickiest. Note that you'll need to add the following references:
- Microsoft.Office.Interop.Word
- System.DirectoryServices
- System.DirectoryServices.AccountManagement...
using Word = Microsoft.Office.Interop.Word;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
protected void PrintLdapProperties()
{
Word.Application oApplication = new Microsoft.Office.Interop.Word.Application();
oApplication.Visible = true;
if (oApplication == null)
{
return;
}
string strDistinguishedName = UserPrincipal.Current.DistinguishedName;
DirectoryEntry oEntry = new DirectoryEntry("LDAP://" + strDistinguishedName);
System.DirectoryServices.PropertyCollection oColl = oEntry.Properties;
Object oMissing = System.Type.Missing;
Word.Document oDocument = oApplication.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
Word.Selection oSelection = oApplication.Selection;
int NumRows = 2;
int NumColumns = 2;
Microsoft.Office.Interop.Word.Table oTable = oSelection.Tables.Add(oSelection.Range, NumRows, NumColumns, ref oMissing, ref oMissing);
Microsoft.Office.Interop.Word.Cell oCell = oTable.Cell(1, 1);
int i = 1;
foreach (string strPropertyName in oColl.PropertyNames)
{
oCell.Select();
oSelection.TypeText(strPropertyName);
oCell.Next.Select();
oSelection.TypeText(oColl[strPropertyName].Value.ToString());
oTable.Rows.Add(ref oMissing);
oCell = oTable.Cell(i + 1, 1);
i++;
}
}
No comments:
Post a Comment