当前位置: 首页>>代码示例>>C#>>正文


C# Application.GetNamespace方法代码示例

本文整理汇总了C#中Application.GetNamespace方法的典型用法代码示例。如果您正苦于以下问题:C# Application.GetNamespace方法的具体用法?C# Application.GetNamespace怎么用?C# Application.GetNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Application的用法示例。


在下文中一共展示了Application.GetNamespace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetOutlookApplication

 private void GetOutlookApplication(out bool disposeOutlookInstances,
   out Application application,
   out NameSpace nameSpace, string profileName)
 {
     // Check whether there is an Outlook process running.
     if (Process.GetProcessesByName("OUTLOOK").Any())
     {
         // If so, use the GetActiveObject method to obtain the process and cast it to an Application object.
         application =
             Marshal.GetActiveObject("Outlook.Application") as Application;
         disposeOutlookInstances = false;
         nameSpace = null;
         if (application != null)
         {
             nameSpace = application.GetNamespace("MAPI");
             if (!string.IsNullOrEmpty(profileName) && !nameSpace.CurrentProfileName.Equals(profileName))
             {
                 throw new InvalidOperationException(
                     $"Current Outlook instance is opened with a Different Profile Name ({nameSpace.CurrentProfileName}).{Environment.NewLine}Close Outlook and try again.");
             }
         }
     }
     else
     {
         // If not, create a new instance of Outlook and log on to the default profile.
         application = new Application();
         nameSpace = application.GetNamespace("MAPI");
         nameSpace.Logon(profileName, "", false, true);
         disposeOutlookInstances = true;
     }
 }
开发者ID:starvator,项目名称:CalendarSyncplus,代码行数:31,代码来源:OutlookTaskService.cs

示例2: OutlookCalendar

        public OutlookCalendar()
        {
            // Create the Outlook application.
            Application oApp = new Application();

            // Get the NameSpace and Logon information.
            // Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("mapi");
            NameSpace oNS = oApp.GetNamespace("mapi");

            //Log on by using a dialog box to choose the profile.
            oNS.Logon("", "", true, true);

            //Alternate logon method that uses a specific profile.
            // If you use this logon method,
            // change the profile name to an appropriate value.
            //oNS.Logon("YourValidProfile", Missing.Value, false, true);

            // Get the Calendar folder.
            UseOutlookCalendar = oNS.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);

            //Show the item to pause.
            //oAppt.Display(true);

            // Done. Log off.
            oNS.Logoff();
        }
开发者ID:rantsi,项目名称:outlookgooglesync,代码行数:26,代码来源:OutlookCalendar.cs

示例3: Excute

        public override void Excute()
        {
            string Result = "";
            Application OutLookApp = new Application();
            NameSpace OutlookNS = OutLookApp.GetNamespace("MAPI");
            MAPIFolder theCal = OutlookNS.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
            if (theCal.Items.Count == 0)
            {
                Result = "No Appointment";
            }
            else
            {
                foreach (AppointmentItem appointment in theCal.Items)
                {

                    /*if (task.Status != OlTaskStatus.olTaskComplete)
                    {
                        Result += String.Format("\n{0}, Due({1})", task.Subject, task.DueDate);

                    }*/
                    Result += String.Format("\n{0}\n", appointment.Subject);
                    Result += "Location : " + appointment.Location + "\n";
                    if (appointment.AllDayEvent)
                        Result += String.Format("{0} (All day)\n", appointment.Start.ToShortDateString());
                    else if (appointment.Start.Subtract(appointment.End).Days == 0)
                    {
                        Result += String.Format("{0} ({1} - {2})\n", appointment.Start.ToShortDateString(), appointment.Start.ToShortTimeString(), appointment.End.ToShortTimeString());
                    }
                    else
                        Result += String.Format("{0} {1} - {2} {3}\n", appointment.Start.ToShortTimeString(), appointment.Start.ToShortDateString(), appointment.End.ToShortTimeString(), appointment.End.ToShortDateString());
                    Result += "\n";
                }
            }
            CallProcess(new ExcutionResult(ResultFlag.Result, "", Result));
        }
开发者ID:charuwat,项目名称:code,代码行数:35,代码来源:CalendarCommand.cs

示例4: ReadPst

        private static IEnumerable<MailItem> ReadPst(string pstFilePath)
        {
            List<MailItem> mailItems = new List<MailItem>();
            Application app = new Application();
            NameSpace outlookNameSpace = app.GetNamespace("MAPI");
            // Add PST file (Outlook Data File) to Default Profile
            outlookNameSpace.AddStore(pstFilePath);

            string pstName = null;

            foreach (Store s in outlookNameSpace.Stores)
            {
                if(s.FilePath.Equals(pstFilePath))
                    pstName = s.DisplayName;
            }

            MAPIFolder rootFolder = outlookNameSpace.Stores[pstName].GetRootFolder();

            Folders subFolders = rootFolder.Folders;
            foreach (Folder folder in subFolders)
            {
                ExtractItems(mailItems, folder);
            }
            // Remove PST file from Default Profile
            outlookNameSpace.RemoveStore(rootFolder);
            Console.WriteLine(mailItems.Count);
            return mailItems;
        }
开发者ID:mtotheikle,项目名称:EWU-OIT-SSN-Scanner,代码行数:28,代码来源:Parser.cs

示例5: Connect

		public bool Connect()
		{
			try
			{
				_outlookObject =
					System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application") as Application;
			}
			catch
			{
				_outlookObject = null;
			}
			if (_outlookObject == null)
			{
				try
				{
					_outlookObject = new Application();
					var folder = (_outlookObject.GetNamespace("MAPI")).GetDefaultFolder(OlDefaultFolders.olFolderInbox);
					folder.Display();
					_outlookObject.Explorers.Add(folder, OlFolderDisplayMode.olFolderDisplayNormal);
				}
				catch
				{
					return false;
				}
			}
			return true;
		}
开发者ID:w01f,项目名称:VolgaTeam.SalesLibrary,代码行数:27,代码来源:OutlookHelper.cs

示例6: Excute

        public override void Excute()
        {
            string Result = "";
            Application OutLookApp = new Application();
            NameSpace OutlookNS = OutLookApp.GetNamespace("MAPI");
            MAPIFolder theTasks =OutlookNS.GetDefaultFolder(OlDefaultFolders.olFolderTasks);

            if (theTasks.Items.Count == 0)
            {
                Result = "No Task";
            }
            else
            {
                foreach (TaskItem task in theTasks.Items)
                {

                    if (task.Status != OlTaskStatus.olTaskComplete)
                    {
                        Result += String.Format("\n{0}, Due({1})", task.Subject, task.DueDate.ToShortDateString());

                    }
                }
            }
            CallProcess(new ExcutionResult(ResultFlag.Result,"",Result));
        }
开发者ID:charuwat,项目名称:code,代码行数:25,代码来源:TaskCommand.cs

示例7: Initialize

 private void Initialize()
 {
     Log.Info("Initializing...");
     OutlookApplication = new Application();
     MapiNameSpace = OutlookApplication.GetNamespace("MAPI");
     CalendarFolder = MapiNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
 }
开发者ID:OpenNingia,项目名称:OpenCalendarSync,代码行数:7,代码来源:OutlookCalendarManager.cs

示例8: ThisAddIn_Startup

 private void ThisAddIn_Startup(object sender, System.EventArgs e)
 {
     string pstFilePath = "sample.pst";
     Outlook.Application app = new Application();
     NameSpace outlookNs = app.GetNamespace("MAPI");
     // Add PST file (Outlook Data File) to Default Profile
     outlookNs.AddStore(pstFilePath);
     MAPIFolder rootFolder = outlookNs.Stores["sample"].GetRootFolder();
     // Traverse through all folders in the PST file
     // TODO: This is not recursive
     Folders subFolders = rootFolder.Folders;
     foreach (Folder folder in subFolders)
     {
         Items items = folder.Items;
         foreach (object item in items)
         {
             if (item is MailItem)
             {
                 // Retrieve the Object into MailItem
                 MailItem mailItem = item as MailItem;
                 Console.WriteLine("Saving message {0} ....", mailItem.Subject);
                 // Save the message to disk in MSG format
                 // TODO: File name may contain invalid characters [\ / : * ? " < > |]
                 mailItem.SaveAs(@"\extracted\" + mailItem.Subject + ".msg", OlSaveAsType.olMSG);
             }
         }
     }
     // Remove PST file from Default Profile
     outlookNs.RemoveStore(rootFolder);
 }
开发者ID:ruanzx,项目名称:Aspose_Email_NET,代码行数:30,代码来源:ThisAddIn.cs

示例9: EnviarHTmlEmail

        /*
        public static ResultadoTransaccion EnviarHTmlEmail(string toValue, string subjectValue, string bodyValue)
        {
            ResultadoTransaccion res = new ResultadoTransaccion();
            try
            {
                oApp = new Application();
                oNameSpace = oApp.GetNamespace("MAPI");
                oOutboxFolder = oNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderSentMail);
                _MailItem oMailItem = (_MailItem)oApp.CreateItem(OlItemType.olMailItem);
                oMailItem.To = toValue;
                oMailItem.Subject = subjectValue;
                if (oMailItem.HTMLBody.IndexOf("</BODY>") > -1)
                    oMailItem.HTMLBody = oMailItem.HTMLBody.Replace("</BODY>", bodyValue);

                oMailItem.SaveSentMessageFolder = oOutboxFolder;
                oMailItem.BodyFormat = OlBodyFormat.olFormatHTML;

                oMailItem.Send();

                res.Estado = Enums.EstadoTransaccion.Aceptada;
            }
            catch (Exception ex)
            {
                res.Descripcion = ex.Message;
                res.Estado = Enums.EstadoTransaccion.Rechazada;

                Log.EscribirLog(ex.Message);
            }

            return res;

        }
        */
        /// <summary>
        /// Metodo para el envio de Email desde el Modulo Calendario
        /// </summary>
        /// <param name="toValue">Email del receptor</param>
        /// <param name="subjectValue">Asunto del Email</param>
        /// <param name="bodyValue">Cuerpo del Email</param>        
        public static ResultadoTransaccion EnviarEmail(string toValue, string subjectValue, string bodyValue)
        {
            ResultadoTransaccion res = new ResultadoTransaccion();
            try
            {
                oApp = new Application();
                oNameSpace = oApp.GetNamespace("MAPI");
                oOutboxFolder = oNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderSentMail);
                _MailItem oMailItem = (_MailItem)oApp.CreateItem(OlItemType.olMailItem);
                oMailItem.To = toValue;
                oMailItem.Subject = subjectValue;
                oMailItem.Body = bodyValue;
                oMailItem.SaveSentMessageFolder = oOutboxFolder;
                oMailItem.BodyFormat = OlBodyFormat.olFormatRichText;

                oMailItem.Send();

                res.Estado = Enums.EstadoTransaccion.Aceptada;
            }
            catch (Exception ex)
            {
                res.Descripcion = ex.Message;
                res.Estado = Enums.EstadoTransaccion.Rechazada;

                Log.EscribirLog(ex.Message);
            }

            return res;
        }
开发者ID:TarekMulla,项目名称:cra,代码行数:69,代码来源:EnvioEmail.cs

示例10: ConversationTracking

		public ConversationTracking(IMailSelector selection)
		{
            _outlookApplication = new Application();
            _ns = _outlookApplication.GetNamespace("MAPI");
			_sent = _ns.GetDefaultFolder(OlDefaultFolders.olFolderSentMail);
			_selection = selection;
			Logger.LogInfo("EMAILTRACKING: Initialised Conversation Tracking");
		}
开发者ID:killbug2004,项目名称:WSProf,代码行数:8,代码来源:ConversationTracking.cs

示例11: MailSelection

		public MailSelection()
		{
            _outlookApplication = new Application();
            _ns = _outlookApplication.GetNamespace("MAPI");
            _inspector = _outlookApplication.ActiveInspector();
            _explorer = _outlookApplication.ActiveExplorer();
			Logger.LogInfo("EMAILTRACKING: Initialised Mail Selection");
		}
开发者ID:killbug2004,项目名称:WSProf,代码行数:8,代码来源:MailSelection.cs

示例12: OutlookWrapper

        public OutlookWrapper()
        {
            OutlookApplication = new Application();
            OutlookNameSpace = OutlookApplication.GetNamespace("MAPI");

            // Automatically log in.

            OutlookNameSpace.Logon(Profile: null, Password: null, NewSession: false, ShowDialog: false);
        }
开发者ID:slowmonkey,项目名称:GmailCalendarSync,代码行数:9,代码来源:OutlookWrapper.cs

示例13: SimpleFinder

        public SimpleFinder(IMeetingRoomRepository rep)
        {
            outlookApp = new Microsoft.Office.Interop.Outlook.Application();
            outlookNs = outlookApp.GetNamespace("MAPI");
            roomRepository = rep;

            foreach (MeetingRoom mr in roomRepository.MeetingRooms)
            {
                recRooms.Add(outlookNs.CreateRecipient(mr.Email));
            }
        }
开发者ID:wangning81,项目名称:Bookit,代码行数:11,代码来源:SimpleFinder.cs

示例14: Send

        public void Send(System.Net.Mail.MailMessage message)
        {
            if (!OutlookIsRunning)
            {
                LaunchOutlook();
            }
            Recipients oRecips = null;
            Recipient oRecip = null;
            MailItem oMsg = null;

            try
            {
                _myApp = new Application();

                oMsg = (MailItem)_myApp.CreateItem(OlItemType.olMailItem);

                oMsg.HTMLBody = message.Body;
                oMsg.Subject = message.Subject;
                oRecips = (Recipients)oMsg.Recipients;


                foreach (var email in message.To)
                {
                    oRecip = (Recipient)oRecips.Add(email.Address);
                }

                foreach (var email in message.CC)
                {
                    oMsg.CC += string.Concat(email, ";");
                }

                List<string> filenames = Attach(message.Attachments, oMsg);
                oRecip.Resolve();

                (oMsg as _MailItem).Send();

                _mapiNameSpace = _myApp.GetNamespace("MAPI");
           

                DeleteTempFiles(filenames);
                Thread.Sleep(5000);
            }
            finally
            {
                if (oRecip != null) Marshal.ReleaseComObject(oRecip);
                if (oRecips != null) Marshal.ReleaseComObject(oRecips);
                if (oMsg != null) Marshal.ReleaseComObject(oMsg);
                if (_mapiNameSpace != null) Marshal.ReleaseComObject(_mapiNameSpace);
                if (_myApp != null) Marshal.ReleaseComObject(_myApp);
            }

        }
开发者ID:rcarubbi,项目名称:Carubbi.Components,代码行数:52,代码来源:OutlookInteropSender.cs

示例15: SendEmail

        public void SendEmail(string sender, string recipient, string subject, string body)
        {
            Application app = new Application();
            var mapi = app.GetNamespace("MAPI");
            mapi.Logon(ShowDialog: false, NewSession: false);
            var outbox = mapi.GetDefaultFolder(OlDefaultFolders.olFolderOutbox);

            MailItem email = app.CreateItem(OlItemType.olMailItem);
            email.To = recipient;
            email.Subject = subject;
            email.Body = body;
            email.Send();
        }
开发者ID:niuniuliu,项目名称:CSharp,代码行数:13,代码来源:OutlookSendEmail.cs


注:本文中的Application.GetNamespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。