Windows 8 Active Tiles not appearing when setting image as URL with Windows Authentication

I’d created Active Tiles using a Background task exactly as other tutorials said to and when using a text only active tile, the process worked fine. But whenever I specified an Image using a web URL the tiles simply did not appear. This had me stumped for ages and nothing useful was appearing in the event log other than “The message id for the desired message could not be found”. Useless!

After much scratching of heads I worked out that the Tile image URL does not work if the image sits on a web site which uses any kind of authentication mechanism such as Windows or Claims based. i.e. applications such as MS SharePoint or MS Dynamics CRM. The solution I cam up with was to download the image locally in the background task where you can specify client credentials and then reference it from the application temporary storage in the Tile.

Here is the code I used below. The Background task calls an async method to populate the tiles based on the results of an RSS feed.

using MyCompany.Windows8.App.MyCompanyNewsReaderHelper.DataModel;
using MyCompany.Windows8.App.MyCompanyNewsReaderHelper.Model;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using Windows.ApplicationModel.Background;
using Windows.Data.Xml.Dom;
using Windows.Storage;
using Windows.UI.Notifications;

namespace MyCompany.Windows8.App.MyCompanyNewsBackgroundTasks
    public sealed class MyCompanyNewsTileUpdater : IBackgroundTask

        private List<FeedItem> _feedItems;
        private volatile object _lockFeedItemsList = new object();
        private IBackgroundTaskInstance taskInstance;
        private BackgroundTaskDeferral defferal;

        public void Run(IBackgroundTaskInstance taskInstance)
            defferal = taskInstance.GetDeferral();
                this.taskInstance = taskInstance;
                Debug.WriteLine("Trying to update MyCompanyNews Tile");
                FeedsDataSource.Instance.LoadFeedsParallel(true, false);

            catch (Exception ex)
                Debug.WriteLine("RSS Exception : " + ex.ToString());

        private void RegisterDataSourceEvents()
            FeedsDataSource.Instance.FeedItemsAdded += OnFeedItemsAdded;
            FeedsDataSource.Instance.FeedItemsCleared += OnFeedItemsCleared;
            FeedsDataSource.Instance.FeedItemsLoadingCompleted += OnFeedItemsLoadingCompleted;

        private async void OnFeedItemsLoadingCompleted(object sender, FeedItemsLoadingCompletedEventArgs feedItemsLoadingCompletedEventArgs)
            Debug.WriteLine("Rss feed loading complete");
            _feedItems = FeedsDataSource.Instance.FeedItems;

           Debug.WriteLine(String.Format("Loaded {0} RSS items",_feedItems.Count.ToString()));
           var updater = TileUpdateManager.CreateTileUpdaterForApplication();

           int i = 0;
           foreach (FeedItem item in _feedItems)
               Debug.WriteLine("trying to load tile for post " + item.Title);
               if (!String.IsNullOrEmpty(item.mainImageUrl))
                   // Unfortunately it seems that when the tile displays the image from a direct URL
                   // Windows authentication is supported. But it is here so we will download the image to application
                   Uri imgLocation = await GetLocalImageAsync(item.mainImageUrl, item.UniqueId);
                   var tileWide = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideSmallImageAndText03);
                   var tileWideVisual = tileWide.GetElementsByTagName("visual");
                   ((XmlElement)tileWideVisual[0]).SetAttribute("branding", "logo");

                   var textNodes = tileWide.GetElementsByTagName("text");
                   var tileImageAttributes = tileWide.GetElementsByTagName("image");
                   Debug.WriteLine("image URL is " + item.thumbnailImageUrl);
                   ((XmlElement)tileImageAttributes[0]).SetAttribute("src", imgLocation.AbsoluteUri);
                   ((XmlElement)tileImageAttributes[0]).SetAttribute("alt", "red graphic");

                   Debug.WriteLine("XML is " + tileWide.GetXml());
                   updater.Update(new TileNotification(tileWide));


               // We can only store 4 tiles at a time
               if (i > 4)

           Debug.WriteLine("Finished updating tiles");

        private void OnFeedItemsAdded(object sender, FeedItemsAddedEventArgs e)
            Debug.WriteLine("Feed item added");
            _feedItems = FeedsDataSource.Instance.FeedItems;

        private void OnFeedItemsCleared(object sender, FeedItemsClearedEventArgs feedItemsClearedEventArgs)
            Debug.WriteLine("Feed items cleared");
                _feedItems = null;

        private async Task<Uri> GetLocalImageAsync(string internetUri, string uniqueName)
            if (string.IsNullOrEmpty(internetUri))
                return null;

            HttpWebRequest theRequest = HttpWebRequest.CreateHttp(internetUri);
            theRequest.UseDefaultCredentials = true;

            using (var response = await theRequest.GetResponseAsync())
                using (var stream = response.GetResponseStream())
                    var desiredName = string.Format("{0}.jpg", uniqueName);
                    var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(desiredName, CreationCollisionOption.ReplaceExisting);

                    List<Byte> allBytes = new List<byte>();
                    using (Stream imageStream = response.GetResponseStream())
                        byte[] buffer = new byte[4000];
                        int bytesRead = 0;
                        while ((bytesRead = await imageStream.ReadAsync(buffer, 0, 4000)) > 0)
                    await FileIO.WriteBytesAsync(file, allBytes.ToArray()); 

                    return new Uri(string.Format("ms-appdata:///local/{0}.jpg", uniqueName), UriKind.Absolute);


Leave a Comment

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