try catch
Er igang med at lave et program, som kommunikere med Active directory. Jeg vil have det kommer op med en fejlmeddelse, hvis den ikke kan fange ad'et. hvor skal jeg ligge min try/catch****************************************************************
private void tmStartup_Tick(object sender, EventArgs e)
{
//\\nike\redirects$\afs\Application Data\Microsoft\Signatures
try
{
this.tmStartup.Enabled = false;
string adEntryPath = ConfigurationManager.AppSettings["AD.LdapPath"];
this.Cursor = Cursors.WaitCursor;
//Load AD users
DirectoryEntry ad = new DirectoryEntry(adEntryPath);
DirectorySearcher searcher = new DirectorySearcher(ad);
searcher.Filter = "(&(objectCategory=person)(objectClass=user)(initials=*))";
SearchResultCollection results = searcher.FindAll();
}
catch (Exception ex)
{
Messagebox.show(String.format("Cannot connect to ad: {0}", ex.Message));
}
Int32 resultCount = results.Count;
foreach (SearchResult result in results)
{
DirectoryEntry userEntry = result.GetDirectoryEntry();
if (userEntry.Properties.Contains("initials"))
{
if (userEntry.Properties["initials"].Value.ToString() != "")
Men jeg kan ikke få det til at fungere, hvor har jeg lavet fejlen??