2013년 2월 24일 일요일

C# vsto outlook pst AddStore name



VB


Sub SetNewStore(strFileName as String, strDisplayName as String)
   Dim objOL as Outlook.Application.   
   Dim objNS as Outlook.Namespace
   Dim objFolder as Outlook.MAPIFolder
    
   Set objOL = CreateObject("Outlook.Application")
   Set objNS = objOL.GetNamespace("MAPI")
   objNS.AddStore strFileName
   Set objFolder = objNS.Folders.GetLast
   objFolder.Name = strDisplayName
 
   Set objOL = Nothing
   Set objNS = Nothing
   Set objFolder = Nothing
End Sub


C#

public static bool AddNewPostBox(Microsoft.Office.Interop.Outlook.Application Application, string pstPath, string foldername) { bool ret = false; Microsoft.Office.Interop.Outlook.NameSpace ns = null; try { ns = Application.GetNamespace("MAPI"); ns.AddStore(pstPath); Outlook.MAPIFolder folderInbox = ns.Folders.GetLast(); folderInbox.Name = foldername; ret = true; } catch (Exception ex) { //MessageBox.Show("Error: " + ex.Message); } finally { if (ns != null) Marshal.ReleaseComObject(ns); } return ret; }

댓글 없음: