Skip to main content

Adding Document Favorite links for Direct File Access in OWA 2007 via a script

Direct File access is a pretty cool feature of OWA 2007 although may not be the easiest thing for your average user to get their head around. Somebody asked a question about pre-populating the favorites for a user which is a pretty good idea (actually when you think about it you really want something that’s policy driven). Currently there is no really easy or supported way of doing this programmatically. The document links themselves are stored in a storage item with a messageclass of IPM.Configuration.Owa.DocumentLibraryFavorites in the associated folder collection of NON_IPM_Subtree root of a mailbox. On this storage item there is a binary mapi property 0x7C080102 and the links are stored in a XML document.

I decided to see if I could write a script that could open this storage item and then add some nodes into the already existing property or create the property if it didn’t exist. The format of the doclib node looks something like

<docLib uri="file://sername/directory" dn="DisplayName"
hn="servername" uf="2"/>

This isn’t documented anywhere so I can only hazard to guess at that these elements actually mean but logically I would think

Uri - Path to the directory or sharepoint server

Dn – The displayName in OWA

Hn – HostName ?

Uf – This property seems to get set to one of 3 values which affects the way the icon shows in OWA if you have added just a hostname then it gets set to 2, if you add a share mapping it gets set to 6 if you added a deep url mapping eg a couple of directorys deep it gets set to 34.

From what I’ve noticed the IPM.Configuration.Owa.DocumentLibraryFavorites storage item only gets created the first time the user click on the documents link in OWA so the item wouldn’t be there normally if the user has not logged onto OWA or has never clicked this link.

As I said this script is unsupported and pretty untested and should only be used in test/dev environment. Also make sure you know how to use a Mapi editor like Outlook Spy or mfcMapi worse case is you’ll stuff up the IPM.Configuration.Owa.DocumentLibraryFavorites object and need to delete it.

The script uses CDO 1.2 to use the script you need to configure the first 4 lines which reflect the doclib I just talked about,

shareDN = "temp"
ShareHostName = "servername"
Shareuf = "6"
ShareURI = "file://servername/temp"

and then the 6,7 with the servername and mailboxname of the mailbox you want to access.

I’ve put a download of the script here the code itself look like

shareDN = "temp"
ShareHostName = "servername"
Shareuf = "6"
ShareURI = "file://servername/temp"

snServername = "mailserver"
mbMailboxName = "mailbox"

Const PR_PARENT_ENTRYID = &H0E090102
set xdXmlDocument = CreateObject("Microsoft.XMLDOM")
ifound = false
Set objSession = CreateObject("MAPI.Session")
objSession.Logon "","",false,true,true,true,snServername & vbLF & mbMailboxName
Set CdoInfoStore = objSession.GetInfoStore
Set CdoFolderRoot = CdoInfoStore.RootFolder
set non_ipm_rootfolder =
For Each soStorageItem in non_ipm_rootfolder.HiddenMessages
If soStorageItem.Type = "IPM.Configuration.Owa.DocumentLibraryFavorites" Then
ifound = true
Set actionItem = soStorageItem
End if
If ifound = false Then
wscript.echo "No Storage Item Found"
On Error Resume Next
hexString = actionItem.fields(&h7C080102).Value
If Err.number <> 0 Then
On Error goto 0
wscript.echo "Property not set"
actionItem.fields.Add &h7C080102, vbBlob
actionItem.fields(&h7C080102).Value = StrToHexStr("<docLibs></docLibs>")
hexString = actionItem.fields(&h7C080102).Value
End If
On Error goto 0
wscript.echo hextotext(hexString)
Set xnNodes = xdXmlDocument.selectNodes("//docLibs")
update = false
Call Adddoclib(shareDN,ShareHostName,Shareuf,ShareURI,xnNodes)
If update = True Then
nval = StrToHexStr(CStr(xdXmlDocument.xml))
actionItem.fields(&h7C080102).Value = nval
wscript.echo "Storage Object Updated"
wscript.echo "No Updates Performed"
End If
End If

Function hextotext(binprop)
arrnum = len(binprop)/2
redim aout(arrnum)
slen = 1
for i = 1 to arrnum
if CLng("&H" & mid(binprop,slen,2)) <> 0 then
aOut(i) = chr(CLng("&H" & mid(binprop,slen,2)))
end if
slen = slen+2
hextotext = join(aOUt,"")
end Function

Function StrToHexStr(strText)
Dim i, strTemp
For i = 1 To Len(strText)
strTemp = strTemp & Right("0" & Hex(Asc(Mid(strText, i, 1))), 2)
StrToHexStr = Trim(strTemp)
End Function

Function Searchfordoclib(elElementName,cnvalue,XMLDoc)
Set xnSearchNodes = XMLDoc.selectNodes("//*[@" & elElementName & " = '" &
cnvalue & "']")
If xnSearchNodes.length = 0 Then
Searchfordoclib = False
Searchfordoclib = True
End if

End Function

sub Adddoclib(dn,hn,uf,uri,xnNodes)
If Searchfordoclib("dn",dn,xdXmlDocument) = False then
Set objnewEle = xdXmlDocument.createElement("docLib")
objnewEle.setAttribute "uri",uri
objnewEle.setAttribute "dn",dn
objnewEle.setAttribute "hn", hn
objnewEle.setAttribute "uf", uf
xnNodes(0).appendchild objnewEle
update = true
wscript.echo "Dn exists " & DN
End if
End sub

Popular posts from this blog

Export calendar Items to a CSV file using EWS and Powershell

Somebody asked about this last week and while I have a lot of EWS scripts that do access the Calendar I didn't have a simple example that just exported a list of the Calendar events with relevant information to a CSV file so here it is.

I've talked on this one before in this howto  but when you query the calendar folder using EWS you need to use a CalendarView which will expand any recurring appointments in a calendar. There are some limits when you use a calendarview in that you can only return a maximum of 2 years of appointments at a time and paging will limit the max number of items to 1000 per call. So if you have a calendar with a very large number of appointments you need to break your query into small date time blocks. In this example script I'm just grabbing the next 7 days of appointments if you want to query a longer period you need to adjust the following lines (keeping in mind what I just mentioned)

#Define Date to Query
$StartDate = (Get-Date)
$EndDate = (Ge…

EWS Managed API and Powershell How-To series Part 1

I thought I'd start the year with a series of posts that goes back over the basics of using the EWS Managed API from Powershell and provides a modular remarked example that you can easily cut and paste to build your own scripts. Along the way in this series I'll show a whole bunch of examples around specific things.

As a starting point for versions this will be Powershell Version 2.0  and the EWS Managed API 1.1 (which will soon change to 1.2 once released)

The starting point for any EWS script your going to write is connecting to Exchange for which there are three important pieces of information you will need. Firstly you need to know the version of Exchange your running in this script its going to be held in the following variable

$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1

Other valid values for Exchange 2007 would be

$ExchangeVersion = [Microsoft.Exchange.WebServices.…

Writing a simple scripted process to download attachmentts in Exchange 2007/ 2010 using the EWS Managed API

Every complicated thing in life is made up of smaller simpler building blocks, when it comes to writing a script (or any code really) the more of these little building blocks you have to figure out the more the process of solving a problem can become bewildering. The Internet generally provides you with lots of half eaten sandwiches of information something someone else has taken a bite out but a lot of the time half done, and as with any code its usefulness declines over time as new and better API's and methods are derived. In this post I'm going to go through a simple scripted process that hopefully covers a few more of these smaller building blocks that you might face when asked to come up with a simple costless solution to perform an automated business function with a script.

So the process im going to look at is one that comes up a lot and that is you have an Email that comes into to certain mailbox every day with a certain subject in my case "Daily Export" this …
All sample scripts and source code is provided by for illustrative purposes only. All examples are untested in different environments and therefore, I cannot guarantee or imply reliability, serviceability, or function of these programs.

All code contained herein is provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.