private void btnDocumentsFiletypes_Click(object sender, EventArgs e)
        {
            FiletypesForm NewFiletypesForm = new FiletypesForm();
            string        sql = "select DISTINCT(Filetype) from Documents (nolock) where Location <> dbo.OwnLocation() and [DOCUMENT] is not null";
            {
                var withBlock = NewFiletypesForm.clbFiletypes;
                withBlock.Items.Clear();
                var ds = mssql.SQLSelect(sql, con);
                if (ds != null && ds.Tables.Count > 0)
                {
                    foreach (DataRow value in ds.Tables[0].Rows)
                    {
                        withBlock.Items.Add(value.ItemArray[0]);
                    }
                }

                foreach (string value in DocumentFiletypes)
                {
                    for (var i = 0; i <= withBlock.Items.Count - 1; i++)
                    {
                        if (withBlock.Items[i].Equals(value))
                        {
                            withBlock.SetItemChecked(i, true);
                        }
                    }
                }
                if (withBlock.Items.Count == 0)
                {
                    MessageBox.Show("Es wurden keine Dateiendung in der Datenbank gefunden. Die Option wird jetzt autoamtisch deaktivert.");
                    btnDocumentsFiletypes.Enabled = false;
                    chkDocumentsFiletypes.Checked = false;
                }
                else

                if (DocumentFiletypes.Count == 0)
                {
                    for (int i = 0; i <= withBlock.Items.Count - 1; i++)
                    {
                        withBlock.SetItemCheckState(i, CheckState.Checked);
                    }
                }
                if (NewFiletypesForm.ShowDialog(this) == DialogResult.OK)
                {
                    DocumentFiletypes.Clear();
                    foreach (string value in withBlock.CheckedItems)
                    {
                        DocumentFiletypes.Add(value);
                    }
                    if (DocumentFiletypes.Count == 0)
                    {
                        btnDocumentsFiletypes.Enabled = false;
                        chkDocumentsFiletypes.Checked = false;
                    }
                }
            }
        }
 private void btnAttachmentsFiletypes_Click(object sender, EventArgs e)
 {
     FiletypesForm NewFiletypesForm = new FiletypesForm();
     string        sql = "select DISTINCT RIGHT(UPPER(FILENAME),PATINDEX('%.%', REVERSE(UPPER(FILENAME)))-1) from MessagesAttachments (nolock) where Location <> dbo.OwnLocation() and [ATTACHMENT] is not null and len(isnull(contentid,'')) = 0";
     {
         var withBlock = NewFiletypesForm.clbFiletypes;
         withBlock.Items.Clear();
         var ds = mssql.SQLSelect(sql, con);
         if (ds != null && ds.Tables.Count > 0)
         {
             foreach (DataRow value in ds.Tables[0].Rows)
             {
                 withBlock.Items.Add(value.ItemArray[0]);
             }
         }
         foreach (string value in AttachmentsFiletypes)
         {
             for (var i = 0; i <= withBlock.Items.Count - 1; i++)
             {
                 if (withBlock.Items[i].Equals(value))
                 {
                     withBlock.SetItemChecked(i, true);
                 }
             }
         }
         if (withBlock.Items.Count == 0)
         {
             MessageBox.Show("Es wurden keine Dateiendungen in der Datenbank gefunden. Die Option wird jetzt automatisch deaktiviert.");
             btnAttachmentsFiletypes.Enabled = false;
             chkAttachmentsFiletypes.Checked = false;
         }
         else
         {
             if (AttachmentsFiletypes.Count == 0)
             {
                 for (int i = 0; i <= withBlock.Items.Count - 1; i++)
                 {
                     withBlock.SetItemCheckState(i, CheckState.Checked);
                 }
             }
             if (NewFiletypesForm.ShowDialog(this) == DialogResult.OK)
             {
                 AttachmentsFiletypes.Clear();
                 foreach (string value in withBlock.CheckedItems)
                 {
                     AttachmentsFiletypes.Add(value);
                 }
             }
             if (AttachmentsFiletypes.Count == 0)
             {
                 btnAttachmentsFiletypes.Enabled = false;
                 chkAttachmentsFiletypes.Checked = false;
             }
         }
     }
 }