2013-03-13 5 views
1

초기보기 (사용자 지정보기)를 갖도록 공용 폴더를 설정하려고하지만 Outlook 2007에서 수동으로 수행하는 방법을 알고 있지만 어떤 속성이나 방법도 찾을 수 없습니다. 이 작업을 수행 할 수있는 Interop (폴더 및 MAPI 폴더)에서 사용하십시오.프로그래밍 방식으로 Outlook 폴더 초기보기를 설정하는 방법

Imports NUnit.Framework 
Imports System.Windows.Forms 
Imports System.Net.Mail 
Imports System.Net.Mime 
Imports System.Net 

Imports System.Runtime.InteropServices 
Imports Outlook = Microsoft.Office.Interop.Outlook 

<TestFixture()> 
Public Class TestOutlook 
    <Explicit()> 
    <Test()> 
    Public Sub TestSetFolderInitialView() 
     Dim ol As New Outlook.Application 
     Dim exCatched As Exception = Nothing 
     Try 
      ' Get My Mailbox 
      Dim myFolder As Outlook.MAPIFolder = Nothing 
      For i As Integer = 0 To ol.Session.Folders.Count - 1 
       myFolder = ol.Session.Folders(i + 1) 
       If myFolder.Name = "Mailbox - Rex" Then ' Change it to your mail box name 
        Exit For 
       End If 
      Next 

      ' Get the folder I want to Set initial view 
      Dim testFolder As Outlook.MAPIFolder = Nothing 
      If myFolder IsNot Nothing Then 
       For i As Integer = 0 To myFolder.Folders.Count - 1 
        Dim pFolder = myFolder.Folders(i + 1) 
        If pFolder.Name = "Inbox" Then 
         For Each fol As Outlook.MAPIFolder In pFolder.Folders 
          If fol.Name = "TestFolder" Then 
           testFolder = fol 
           Exit For 
          End If 
         Next 
         Exit For 
        End If 
       Next 
      End If 

      If testFolder IsNot Nothing Then 
       Try 
        ' Create a test view 
        Dim newVw = CType(testFolder.Views.Add("RexTest-" & DateTime.Now.ToString("yyyyMMdd-hhmmss"), 
                    Outlook.OlViewType.olTableView, 
                    Outlook.OlViewSaveOption.olViewSaveOptionThisFolderEveryone), 
              Outlook.TableView) 
        newVw.LockUserChanges = True 
        newVw.Save() 
        newVw.Apply() 

        ' PR_DEFAULT_VIEW_ENTRYID: 
        Dim ns = "http://schemas.microsoft.com/mapi/proptag/" 
        Dim PR_DEFAULT_VIEW_ENTRYID = "0x36160102" 
        Dim PR_FOLDER_XVIEWINFO_E = "0x36E00102" 
        Dim defaultVw = testFolder.PropertyAccessor.GetProperty(ns & PR_DEFAULT_VIEW_ENTRYID) 
        Dim xVwInfo = testFolder.PropertyAccessor.GetProperty(ns & PR_FOLDER_XVIEWINFO_E) 

        ' the defaultVw is nothing for the first time (actually throw exception) 
        ' if i manually change it from the outlook, 
        ' the value will be something like: 000000004B593F3D35EF8C42AB181C105AE444D40700E46C905CB9ABE446AA44351902AFC40E000026BF7A8C000040DB82FE9B98724F9B222A9C9BDB42CD0000005CF0280000 

        ' **** The problem is how to get the correct binary data for the newly created view so i can set it like this: ***** 
        'testFolder.PropertyAccessor.SetProperty(ns & PR_DEFAULT_VIEW_ENTRYID, testFolder.PropertyAccessor.StringToBinary(newVw.Name)) 
       Catch ex As Exception 
        ' _log.Warn(String.Format("Error set initial view {0} to folder - {1}", newVw.Name, testFolder.Name), ex) 
        exCatched = ex 
        ' First time error 'The property "http://schemas.microsoft.com/mapi/proptag/0x36160102" is unknown or cannot be found' will be shown 
        ' If we set the initial view of the folder in the outlook, this error will go away 
       End Try 
      End If 
     Catch ex As Exception 
      Debug.WriteLine(ex.Message) 
      Debug.WriteLine(ex.StackTrace) 
      exCatched = ex 
     Finally 
      If ol IsNot Nothing Then 
       Marshal.ReleaseComObject(ol) 
       ol = Nothing 
      End If 
     End Try 

     If exCatched IsNot Nothing Then 
      Throw exCatched 
     End If 
    End Sub 
End Class 

지금 유일한 왼쪽 부분은 새로 만든 뷰에서 올바른 이진 데이터를 받으시는 방법 : 인터넷 검색의 몇 시간 후

, 나는 다음과 같은 나왔다. 이진 값을 조작하기위한 몇 가지 단서 : http://microsoft.public.win32.programmer.messaging.narkive.com/x1fNHHA5/default-view

그러나 다른 언어로 작성되었으며 VB 또는 C#으로 작성하는 방법을 알지 못합니다.

도움을 주셨습니다.

답변

0

MAPIFolder.CurrentView 및 MAPIFolder.Views를 사용해 보셨습니까?

+0

예, 모든 CurrentView 및보기를 사용하여보기 만 적용 할 수 있지만 폴더의 초기보기로 설정할 수는없는 것처럼 보입니다. – Rex

+0

이 문제가 해결 된 것 같지만 C# 또는 VB로 작성하는 방법을 모르는 경우 - http://microsoft.public.win32.programmer.messaging.narkive.com/x1fNHHA5/default-view – Rex

+0

MAPI 속성을 설정할 수 있습니다 MAPIFolder.PropertyAccessor.SetProperty를 사용하여 폴더에 저장하십시오. –

관련 문제