Second Life of a Hungarian SharePoint Geek

July 6, 2013

Issues with the SharePoint-Outlook connection

Filed under: Bugs, Fiddler, Outlook, SP 2010 — Tags: , , , — Peter Holpar @ 11:20

Issue 1

Recently we received a complain from a user, that synchronizing SharePoint 2010 documents to Outlook 2010 does not work. The error message in Outlook was:

Task ‘SharePoint’ reported error (0x80070005) : ‘You do not have permission to view this SharePoint List HTTP 302’

The conditions were:

SharePoint application with default (HTTPS) and intranet (HTTP) zones, identical host header for the zones. The IIS site for the intranet zone was stopped and redirected to the default zone (HTTP –> HTTPS).

The user was to synchronize two folders of a large document library (accessed using HTTPS) to Outlook 2010. Adding (any) first folder of the library to Outlook was OK, it was synchronized down to Outlook without any problems. However adding (any) second folder of the library gave us the same error. Synchronizing the items in the first folder was working the same time.

Using Fiddler I found, that instead of HTTPS Outlook sends the requests for synchronizations (the GetList method of the Lists web service is called, see details of the communications in a former post) to SharePoint using HTTP. IIS responded with the correct redirection status, HTTP 302, but it was simply ignored by Outlook. It seems to me as a double-bug: first, Outlook should not try to connect using HTTP when we created the connection from a HTTPS site, and second, it should follow the redirection response sent back by IIS.

I found a similar problem in this TechNet forum thread, and questions / conclusions like:

„Does Outlook 2007 not understand http 302 redirections?”

„I suspect Outlook doesn’t handle the redirection right.”

The “solution” in this case was to synchronize the full (quite large) document library, instead of the selected subfolders.

Another workaround might be to use Fiddler to redirect the HTTP request to HTTPS for the specific web site (by extending the default OnBeforeRequest function in CustomRules.js), however, a typical user would not like to run Fiddler in the background just to be able synchronize files from SharePoint.

    static function OnBeforeRequest(oSession: Session) {
       if (oSession.HostnameIs("yoursite.com") && oSession.oRequest.headers.UriScheme == "http") {
         oSession.oRequest.headers.UriScheme = "https";
       }
    … // original code of OnBeforeRequest function

 

Issue 2

We have two (fast) identical SharePoint 2010 systems: a test and a productive environment. Content is the same, FQDN of the servers are different. When I connect a SharePoint document library from prod. to Outlook 2010, it’s synchronized down to the client as expected. However, when I try to connect Outlook to the same library in test, the first link in Outlook simply replaced by the new one, the URL of the connection is overridden by the URL of the library from the test system. Seems to be a bug as well.

January 9, 2013

Creating an Outlook add-in to handle mails waiting in outbox

Filed under: Office add-in, Outlook — Tags: , — Peter Holpar @ 14:01

A few weeks ago I had a network problem that caused a rather strange issue. The (rather important and urgent) mails I sent during the network-outage were waiting in the Outbox in Outlook, so far so good. After the network come back, I thought my mails were sent automatically by Outlook and waited for response from the addresses of the mails, but received none. After a while I’ve checked the Outbox, and the original mails were still there, even in the meantime I sent and received several other mails.

At this point I decided to look up a free Outlook add-in (or the source code of one would be even better) that alerts me in such cases, but surprisingly found none of them, although found a lot of people complaining for problems similar to my experience. So I started to create my custom add-in, using the Outlook 2010 Add-in project template in Visual Studio 2010.

image

The final source code for ThisAddIn.cs is illustrated by the code snippet below.

Code Snippet
  1. using System;
  2. using Microsoft.Office.Interop.Outlook;
  3. // using Outlook = Microsoft.Office.Interop.Outlook;
  4. using Office = Microsoft.Office.Core;
  5. using System.Windows.Forms;
  6.  
  7. namespace OutboxWatcher
  8. {
  9.     public partial class ThisAddIn
  10.     {
  11.         private Timer _timer;
  12.         private MAPIFolder _outbox;
  13.         private bool _promtOpen;
  14.  
  15.         private void ThisAddIn_Startup(object sender, System.EventArgs e)
  16.         {
  17.             _outbox = this.Application.Session.GetDefaultFolder(OlDefaultFolders.olFolderOutbox);
  18.             StartWatching();
  19.         }
  20.  
  21.         private void StartWatching()
  22.         {
  23.             _timer = new Timer();
  24.             // we set a notification interval of 15 secs here
  25.             // that is OK for testing, in real life you should set a much longer duration,
  26.             // not to get disturbed so frequently during your work
  27.             _timer.Interval = 15000;
  28.             _timer.Tick += _timer_Tick;
  29.             _timer.Start();
  30.         }
  31.  
  32.         void _timer_Tick(object sender, EventArgs e)
  33.         {
  34.             // if the former prompt is opened, we don't open anoter one
  35.             if (!_promtOpen)
  36.             {
  37.                 if ((_outbox != null) && (_outbox.Items != null) && (_outbox.Items.Count > 0))
  38.                 {
  39.                     _promtOpen = true;
  40.  
  41.                     // in the offline mode we can't send mails from outbox, so we only display a warning message
  42.                     if (this.Application.Session.Offline)
  43.                     {
  44.                         MessageBox.Show("Outbox is not empty. You are in offline mode.");
  45.                     }
  46.                     else
  47.                     {
  48.                         DialogResult dr = MessageBox.Show("Outbox is not empty. Would you like to send mails now?",
  49.                                    "Outbox is not empty", MessageBoxButtons.YesNo);
  50.                         // try to send mails if requested
  51.                         if (dr == DialogResult.Yes)
  52.                         {
  53.                             SendMails();
  54.                         }
  55.                     }
  56.  
  57.                     _promtOpen = false;
  58.                 }
  59.             }
  60.         }
  61.  
  62.         private void SendMails()
  63.         {
  64.             if ((_outbox != null) && (_outbox.Items != null))
  65.             {
  66.                 foreach (var item in _outbox.Items)
  67.                 {
  68.                     MailItem mailItem = item as MailItem;
  69.                     if (mailItem != null)
  70.                     {
  71.                         mailItem.Send();
  72.                     }
  73.                 }
  74.             }
  75.         }
  76.  
  77.         private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
  78.         {
  79.             _timer.Tick -= _timer_Tick;
  80.             _timer.Stop();
  81.             _timer = null;
  82.             _outbox = null;
  83.         }
  84.  
  85.         #region VSTO generated code
  86.  
  87.         /// <summary>
  88.         /// Required method for Designer support – do not modify
  89.         /// the contents of this method with the code editor.
  90.         /// </summary>
  91.         private void InternalStartup()
  92.         {
  93.             this.Startup += new System.EventHandler(ThisAddIn_Startup);
  94.             this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
  95.         }
  96.         
  97.         #endregion
  98.     }
  99. }

All this add-in does is to periodically check the content of the Outbox. If it is not empty, and Outlook is offline, then it displays a warning message. If we are in a connected mode and the user chooses this option, it tries to send the mails as well. I hope it helps you to avoid such frustrating situations.

December 30, 2011

Synchronizing SharePoint tasks with Outlook including categories

Filed under: Fiddler, Outlook, SP 2010 — Tags: , , — Peter Holpar @ 00:30

Recently one of our customers requested a SharePoint task list that is synchronized with Outlook. That is usually quite easy, but in this case we should have provided a way to tag the tasks and group them based on this multi-value property on the Outlook side, similarly to the default Categories field feature.

As you may know, only a limited set of task properties are synchronized between SharePoint and Outlook, but details –  like what exactly these properties are and how the synchronization process works – are not very well documented.

To investigate the behavior I’ve created a test list called OLTasks based on the Tasks list template in SharePoint.

image

Then connected the list to Outlook.

image

I’ve started Fiddler and found that the Lists web service is used for synchronization. First, the GetList method is called.

image

Next, a GetListItemChangesSinceToken request is sent. This method is suggested by Microsoft for item synchronization. As one can read on MSDN:

“The most efficient way to synchronize third-party clients with Microsoft SharePoint Foundation 2010 is to download only those items that have changed since the last synchronization occurred. You can do this in SharePoint Foundation 2010 by calling the GetListItemChangesSinceToken Web method.”

The first request contains no token, and the response includes the entire list schema (not shown below). Since our task list contains no item, the ItemCount is zero.

image

Note, that the request above contains the Categories property, however, our Task content type has no such field.

image

I’ve created a new task item in the list to see how it is downloaded to Outlook.

image

image

Again, the GetListItemChangesSinceToken method was called, in this case there was a token in the request (changeToken is not shown below due to lack of space) and the value of ItemCount was 1 in response.

image 

After synchronization, the item appeared in Outlook:

image

image

I’ve modified the task description, and found that on the next synchronization the UpdateListItems method was called to upload changes to SharePoint.

image

Before and after calling the UpdateListItems method the GetListItemChangesSinceToken method was called to detect possible conflicts and synchronize back changes from server.

To provide the Categories field for our tasks, I’ve added the existing site column with the same name to the list.

image

image 

Set a test value for the field at the existing task,

image

and created a new one with other test values. Note, that I’ve specified two values in this case, separated by a comma.

image

As expected the values are synchronized down to Outlook, as shown in this view, grouped by the Categories field.

image

When opening Task 2, we found that our category values are not in the Master Category List.

image

We can resolve it – and add some color codes as well – by clicking New… on the dialog box.

image

After this configuration, Outlook handles our categories as known ones. Next, I’ve set a new category for the task in Outlook.

image

The Outlook view reflects the changes.

image

The UpdateListItems method uploads the changes to SharePoint.

image

And the updated values are displayed in our SharePoint list as well.

image

I hope this quick guide helps you to better understand the default synchronization process, and to utilize similar techniques in your applications.

Create a free website or blog at WordPress.com.