Click here to Skip to main content
15,891,033 members
Home / Discussions / C#
   

C#

 
AnswerRe: use of a value in a form in another one Pin
OriginalGriff21-Jan-10 5:06
mveOriginalGriff21-Jan-10 5:06 
QuestionRe: use of a value in a form in another one Pin
sanforjackass21-Jan-10 5:23
sanforjackass21-Jan-10 5:23 
AnswerRe: use of a value in a form in another one Pin
naghoumeh1421-Jan-10 23:49
naghoumeh1421-Jan-10 23:49 
QuestionRe: use of a value in a form in another one Pin
sanforjackass22-Jan-10 0:07
sanforjackass22-Jan-10 0:07 
AnswerRe: use of a value in a form in another one Pin
naghoumeh1425-Jan-10 0:09
naghoumeh1425-Jan-10 0:09 
QuestionSuggestions on developing C# Application Pin
hariprasad_120421-Jan-10 4:15
hariprasad_120421-Jan-10 4:15 
AnswerRe: Suggestions on developing C# Application Pin
Dave Kreskowiak21-Jan-10 6:48
mveDave Kreskowiak21-Jan-10 6:48 
QuestionHow to Create UI AUTOMATION for OUTLOOK 2007 using C# .Net 3.0 (using System.Windows.Automation;) Pin
bruze21-Jan-10 2:08
bruze21-Jan-10 2:08 
Can Any One Help,

I am trying UI AUTOMATION for OUTLOOK 2007 using C# .Net 3.0 (using System.Windows.Automation;)

My Requirement's are mentioned below.

1) Open Outlook 2007
2) Open Inbox
3) Select first unread email.
4) Open the first unread email.
5) If there are attachements, download the attachements.
6) Select next unread email and do the same as above.

I can open the OUTLOOK 2007, But I am getting NULL value while Searching Inbox using PropertyCondition.
PropertyCondition pc = new PropertyCondition(AutomationElement.NameProperty, name);
            return parent.FindFirst(TreeScope.Descendants, pc); 

Here are the Code,

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Automation;
using System.Windows.Automation.Provider;
using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Forms;

namespace AmmeaBahavathi
{
    class OutLookUIAutomation
    {
        [DllImport("user32.dll")]
        private static extern bool SetForegroundWindow(IntPtr hWnd);
        [DllImport("user32.dll")]
        private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
        [DllImport("user32.dll")]
        private static extern bool IsIconic(IntPtr hWnd);
        private const int SW_RESTORE = 9;                

        static void Main(string[] args)
        {           
            // look for outlook already running
            Process[] processes = Process.GetProcessesByName("outlook");
            AutomationElement aeOutLook = null;
            Process proc1 = new Process();
         
            if (processes.Length == 0)
            {
                // start new outlook process              
                proc1.StartInfo.FileName = "outlook";
                proc1.Start();
                proc1.WaitForInputIdle();
                Thread.Sleep(5000);
                aeOutLook = AutomationElement.FromHandle(proc1.MainWindowHandle);
            }
            else
            {
                proc1.Close();
                // pull up the existing outlook window
                IntPtr hWnd = processes[0].MainWindowHandle;
                if (IsIconic(hWnd))
                {
                    ShowWindowAsync(hWnd, SW_RESTORE);
                }
                SetForegroundWindow(hWnd);
            }
                       
            
            if (aeOutLook != null)
            {
                Thread.Sleep(1000);

                //Invoke Inbox
                AutomationElement aeNew = FindAutomationElementByName(aeOutLook, "Inbox");
                if (aeNew != null)
                {                          
                    Thread.Sleep(5000);
                    InvokePattern ipNew = aeNew.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
                    ipNew.Invoke();
                }
                else
                {
                    Console.WriteLine("aeInbox:Null");
                }

            }
            else
            {
                Console.WriteLine("aeOutLook:Null");
            }
            Console.ReadLine();
        }

        public static AutomationElement FindAutomationElementByName(AutomationElement parent, string name)
        {
            PropertyCondition pc = new PropertyCondition(AutomationElement.NameProperty, name);
            return parent.FindFirst(TreeScope.Descendants, pc);            
        }      
    }
}


Thanks,
Bruze
AnswerRe: How to Create UI AUTOMATION for OUTLOOK 2007 using C# .Net 3.0 (using System.Windows.Automation;) Pin
Phil J Pearson21-Jan-10 2:22
Phil J Pearson21-Jan-10 2:22 
GeneralRe: How to Create UI AUTOMATION for OUTLOOK 2007 using C# .Net 3.0 (using System.Windows.Automation;) Pin
bruze21-Jan-10 2:24
bruze21-Jan-10 2:24 
QuestionManagement Scope in connection options Pin
vinothkumar_Dhakshinamoorthy21-Jan-10 1:40
vinothkumar_Dhakshinamoorthy21-Jan-10 1:40 
QuestionTutorial on developing custom\user control in c# Pin
matixsc21-Jan-10 1:08
professionalmatixsc21-Jan-10 1:08 
AnswerRe: Tutorial on developing custom\user control in c# Pin
N a v a n e e t h21-Jan-10 1:32
N a v a n e e t h21-Jan-10 1:32 
AnswerRe: Tutorial on developing custom\user control in c# Pin
Eddy Vluggen21-Jan-10 1:44
professionalEddy Vluggen21-Jan-10 1:44 
GeneralRe: Tutorial on developing custom\user control in c# Pin
matixsc21-Jan-10 2:22
professionalmatixsc21-Jan-10 2:22 
QuestionBatch update in SQL Server Database Pin
sirtimid21-Jan-10 0:32
sirtimid21-Jan-10 0:32 
AnswerRe: Batch update in SQL Server Database Pin
Rob Philpott21-Jan-10 3:11
Rob Philpott21-Jan-10 3:11 
GeneralRe: Batch update in SQL Server Database Pin
sirtimid21-Jan-10 3:20
sirtimid21-Jan-10 3:20 
GeneralRe: Batch update in SQL Server Database Pin
Rob Philpott21-Jan-10 3:39
Rob Philpott21-Jan-10 3:39 
GeneralRe: Batch update in SQL Server Database Pin
sirtimid21-Jan-10 4:00
sirtimid21-Jan-10 4:00 
AnswerRe: Batch update in SQL Server Database Pin
PIEBALDconsult21-Jan-10 3:26
mvePIEBALDconsult21-Jan-10 3:26 
QuestionSelection in ListBox Pin
Anu_Bala21-Jan-10 0:21
Anu_Bala21-Jan-10 0:21 
AnswerRe: Selection in ListBox Pin
Luc Pattyn21-Jan-10 1:18
sitebuilderLuc Pattyn21-Jan-10 1:18 
AnswerRe: Selection in ListBox Pin
freakyit21-Jan-10 3:49
freakyit21-Jan-10 3:49 
GeneralRe: Selection in ListBox Pin
Anu_Bala24-Jan-10 16:41
Anu_Bala24-Jan-10 16:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.