How To Show GAL Photos / Pictures In Exchange 2010 Outlook Web App.

[ 24 ] Comments
Share

I’ve seen a few people asking recently, if it’s possible to get OWA 2010 to show the GAL images that can be inserted in Active Directory (if you don’t know how to do that, I’ll write something about it another day). There’s nothing built in, but it can be done with a simple OWA modification. In fact, you’ll need to make a very small mod to one OWA server-side file, and then add an extra file which I will describe later.

It makes sense to discuss the extra file first. Look for the folder at this location

C:\Program Files\Microsoft\Exchange Server\V14\ClientAccess\Owa\forms\premium

this is where you’ll be working. Within the folder, create a new file named ShowGALPicture.aspx and then open it in Notepad. Insert the following text, and then save it back and close the file. Note that instead of yourdomain.com, you will need to insert your own domain name.

<%@ Page language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Common" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%
try
{
  string strEmail = Request.QueryString["ID"];
  OleDbConnection cn = new OleDbConnection("Provider=ADsDSOObject;dsn=Active Directory Provider");
  cn.Open();
  string strSQL = "SELECT thumbnailPhoto FROM 'LDAP://yourdomain.com'" +
    " WHERE mail='" + strEmail + "'";
  OleDbCommand cmd = new OleDbCommand(strSQL, cn);
  OleDbDataReader rs = cmd.ExecuteReader();
  if(rs.Read())
  {
    Byte[] arrB = (Byte[])rs.GetValue(0);
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("content-disposition", "attachment; filename=GALPicture.jpg");
    Response.BinaryWrite(arrB);
  }
}
catch{}
%>

There’s not a lot of code, is there? Next, look for the file named readadorgperson.aspx. Make a backup copy (in case you break it), and then open it in Notepad. Press F3 to search for the text RenderDisplayName. Ignore the first occurrence, and continue to the second. You will find it in a segment like this:

  <span id="spnTN">
    <%RenderDisplayName();%>
  </span>

first, change the first of those lines to look like this:

   <span id="spnTN" style="vertical-align:top;">

this helps with the formatting a little. Next, insert this code just before the line that says </span>:

<img
src="/owa/forms/premium/ShowGALPicture.aspx?ID=<% GetRecipientPrimarySmtpAddress(); %>"
style="visibility:hidden;"
onload="javascript:this.style.visibility='visible';"
>

this is the bit that actually puts the image in the page. When you’re done, the block should look like this:

  <span id="spnTN" style="vertical-align:top;">
    <%RenderDisplayName();%>
<img
src="/owa/forms/premium/ShowGALPicture.aspx?ID=<% GetRecipientPrimarySmtpAddress(); %>"
style="visibility:hidden;"
onload="javascript:this.style.visibility='visible';"
>
  </span>

Save the file back, and that should be it. When I’ve a bit more time, I’ll add a screen shot to show that it actually works (well it did for me).

As with all these OWA mods, make sure that they are still there after each service pack and rollup. Sometimes your modified files get replaced with new ones.


24 Responses to How To Show GAL Photos / Pictures In Exchange 2010 Outlook Web App.

  1. Alessandro says:

    Very very smart Derby!
    It’s so simple and so great! Thankyou.
    Just a little problem for me reading this post from my android device: the code results cropped by the text box, so even doing a select all-copy-paste, a part of code is missing (but I’ve understood how to do it, that’s the really important thing).
    Alessandro

    • admin says:

      Ciao Alessandro! Thanks for taking the time to get in touch. I’m glad you enjoyed the article. I have to say that I didn’t imagine anyone would try to do this using their smartphone, but well done on working out the missing bits.

  2. Steve says:

    Great blog.

    I couldnt get this line to return anything in Exchange 2010 SP2 Rollup 3 environment:

    string strEmail = Request.QueryString["ID"];

    Any idea why?

  3. admin says:

    Hello Steve. That would be more of an IIS problem, than an Exchange problem, I think. Can I ask how you know it’s not getting the value from the querystring? Since the code sets a content-type of octet-stream, you would see anything displayed like you would normally. If you are not seeing GAL images being output (and you are sure they have been uploaded), try temporarily removing the line that sets the content-type for the output, and you may see some normal error text if something goes wrong.

    To test the code outside of OWA, try typing this address into your browser:

    https://yourServerName/owa/forms/premium/ShowGALPicture.aspx?ID=your@emailaddress.com

    (use your own server name and email address, of course).

    • Steve says:

      I see now. The ID is in the URL request.

      I am new to asp.net and OWA programming. I was trying to use your code to determine the SMTP address of a user logged into OWA..

      I am trying to build a self service page for our OWA users so that they can manage their mailbox size. I’d like to get a logged user the ability to get a on demand report of folders that are taking up most space and a list of messages that are large. These users don’t have access to Outlook client.

      I have most of it down by using EWS and LDAP queries, but it ony works when I hard code a username. Now, I need to determine an identifier of some sort of the logged on user from the OWA session. I have a problem getting this when a CAS server proxies connection to “Back end” m server. In this case I get only identifers of the proxying server and not the user. This is from servervaribles like “AUTH_USER”, “LOGON_USER” and “REMOTE_USER”. It seems like session variables are not availble in Exchange 2010 OWA.

      Thanks,

      Steve

  4. admin says:

    I’m sure you could use LOGON_USER, etc. After all, these are all IIS things, and I don’t think OWA can simply take them away, as it were. But I think HttpRequest.LogonUserIdentity is nicer:
    http://msdn.microsoft.com/en-us/library/system.web.httprequest.logonuseridentity.aspx
    If you want to get the user’s email address at some point in an OWA aspx page, use GetRecipientPrimarySmtpAddress() . This is a function provided by the (specially created) OWA DLLs, though, so it’s not a function you’ll find available outside of OWA. Unless you reference those DLLs, of course.

  5. orlando says:

    Hello Derby,

    Thank you for the write up! this is indeed a highly requested feature.

    I am able to test the code outside of OWA, and a picture was downloaded. However, i dont see the pictures anywhere.

    This is what i have for the placement code:

    <img src="/owa/forms/premium/ShowGALPicture.aspx?ID=”
    style=”visibility:hidden;”
    onload=”javascript:this.style.visibility=’visible’;”
    >

    i added class=”nm”, as that was on the original piece of code, but i’ve tried it without it and still no picture. Any idea what i could be missing?

    here is what i see: http://imgur.com/emXcAhS

    Thanks again!

    • admin says:

      Hello Orlando. The ID parameter is supposed to be the email address of a user in your organization for whom you have uploaded a GAL Photo. The URL you have in your example above ends in ID= (i.e. there is no value for ID), so no photo will be shown. In my article, it gets the email address from the GAL entry, and passes that as the ID parameter.

  6. Kim says:

    Thank you very much, worked like a charm. Much appreciated write up.

  7. Elad says:

    Thank you so much!

    you made it so easy to deploy, really appreciated it.

    working great!

  8. Sathya Paul says:

    Will this work for Exchange 2007 OWA.

    • admin says:

      Hm. I don’t really know, and I don’t have E2007 any more. I should think that in principle, it ought to; but there are bound to be some differences when it comes to modifying the OWA GAL details page. Can you even find the readadorgperson.aspx file on the server? If so, then there’s a good chance the procedure will be similar.

      • Sathya Paul says:

        I followed the process and created the ShowGALPicture.aspx file and did find the readadorgper son.aspx and made the listed changes as below:

        ====================================================================
        span id=”spnTN” style=”vertical-align:top;”>

        <img
        src="/owa/forms/premium/ShowGALPicture.aspx?ID=”
        style=”visibility:hidden;”
        onload=”javascript:this.style.visibility=’visible’;”
        >

        ====================================================================

        post this restarted the iis and performed OAB update… but still cant see the pic’s in OWA.

        any suggestion….

  9. Sam says:

    I did everything you say in your document. Then I go to test and the page is blank. Not sure what I am missing here.

  10. Tamas says:

    This is great, but what I’m really looking for is a way to add it so that the picture will display in the e-mail header like it does in Outlook 2010. I assume it’s a similar process, just editing a different file, but I’m not familiar enough to know which one to modify and I don’t have a test Exchange environment to play around in.

  11. Sathya Paul says:

    I am using Exchange 2007…. what will be the command if i want to bulk import multiple users thumbnailphoto attribute using AD Powershell.

    Regards
    Sathya

  12. Michelle says:

    This is absolutely brilliant and so easily implemented. I have done a lot of research on allowing the end user to select and upload their own photo rather than me use one they loathe but I can’t find anything for OWA2010 though it seems like a built in feature for 2013. Any chance you have another little hack to make this possible?

    Cheers,

    Michelle

    • admin says:

      Hi Michelle. Actually, I did try, but for some reason, I always got permission errors when trying to put the photo into the user’s AD record. I couldn’t work out why, and eventually gave up. Since you’re interested, though, I’ll have another look at it.

      I think there are already some desktop utilities out there that will do it. There doesn’t seem to be a permission problem from the desktop. Only when going via IIS.




Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>