How to set outlook folder initial view programatically -


i want set public folder have initial view (custom view), know how manually on outlook 2007, however, cannot find property or method can use in interop (folder , mapi folder) can this.

after few hours of googling, came out following:

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 new outlook.application         dim excatched exception = nothing         try             ' mailbox              dim myfolder outlook.mapifolder = nothing             integer = 0 ol.session.folders.count - 1                 myfolder = ol.session.folders(i + 1)                 if myfolder.name = "mailbox - rex" ' change mail box name                     exit                 end if             next              ' folder want set initial view             dim testfolder outlook.mapifolder = nothing             if myfolder isnot nothing                 integer = 0 myfolder.folders.count - 1                     dim pfolder = myfolder.folders(i + 1)                     if pfolder.name = "inbox"                         each fol outlook.mapifolder in pfolder.folders                             if fol.name = "testfolder"                                 testfolder = fol                                 exit                             end if                         next                         exit                     end if                 next             end if              if testfolder isnot nothing                 try                     ' create 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)                      ' defaultvw nothing first time (actually throw exception)                     ' if manually change outlook,                      '   value like: 000000004b593f3d35ef8c42ab181c105ae444d40700e46c905cb9abe446aa44351902afc40e000026bf7a8c000040db82fe9b98724f9b222a9c9bdb42cd0000005cf0280000                      ' **** problem how correct binary data newly created view can set this: *****                     'testfolder.propertyaccessor.setproperty(ns & pr_default_view_entryid, testfolder.propertyaccessor.stringtobinary(newvw.name))                 catch ex exception                     ' _log.warn(string.format("error set initial view {0} folder - {1}", newvw.name, testfolder.name), ex)                     excatched = ex                     ' first time error 'the property "http://schemas.microsoft.com/mapi/proptag/0x36160102" unknown or cannot found' shown                     ' if set initial view of folder in outlook, error go away                 end try             end if         catch ex exception             debug.writeline(ex.message)             debug.writeline(ex.stacktrace)             excatched = ex                     if ol isnot nothing                 marshal.releasecomobject(ol)                 ol = nothing             end if         end try          if excatched isnot nothing             throw excatched         end if     end sub end class 

now left part how correct binary data newly created view. clue manipulate binary value: http://microsoft.public.win32.programmer.messaging.narkive.com/x1fnhha5/default-view

however written in different language , got no idea how make in vb or c#.

any appreciated.

have tried mapifolder.currentview , mapifolder.views?


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -