Monday, April 27, 2009

When i work with my calendar web part in SharePoint i got lot of questions and things happend. I configured every thing correctly in My Calendar web part. i.e. Mail server address, Mailbox.
But, when i open the page which contains calendar web part, it prompts for user name and password of SharePoint site and another for the Calendar login . i.e. login page of OWA application. If i provide the credentials it will work very fine.

Now the problem starts. If the same application is trying to access by another users, other than me then they always failed to login to my calendar web part. This is because, in mailbox i given my mail account, when others try to access the web part, it won't work at all. What they need at that time is they will edit the web part, and will change the mail box entry to their own email address. But this is not possible for all users because all users don't have access to edit page/web part.

My Calendar web part is not working for multiple users in SharePoint 2007. When you add the web part on a page, which mail entry you given in the Mail box that account only can login. I will tell you the reason behind it. My calender web part is developed only for the purpose of showing their calendar events on the my site page. My site usually have access to edit/delete etc for current logged in user, so he will see the content belongs to him. But as per my requirements i want to use the calendar on the site other than the my site pages.

To solve the above mentioned problem, i created a custom web part to work for any logged in user. You can get this code and build it, add the appsetting variables in the web.cofig and deploy it to your site, You can get the deploy instructions of web part in MSDN.

Web.Config changes:
We need to provide 2 inputs to the web part.
1. Site Url.
2. Exchange Server Url.

We have setup a job [Usually we will setup while installing SharePoint and configuring the SSP] in your SharePoint server Shared services Provider [SSP], to pull user accounts from the Active Directory to Sharepoint profile database. Because below code gets the emailid automatically from the user profile database depending on the logged in user. And places that emailid in Mail Box entry of the my calendar web part.

Usually, when we configure the Profile import, we will give source and configure the schedule too. i.e. Every day night or every week etc… it pulls data from given source [ex: Active directory] to profile database.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Portal.WebControls;
using Microsoft.SharePoint.Portal.Topology;
using Microsoft.SharePoint.Portal;
using Microsoft.SharePoint.Portal.UserProfiles;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;namespace MyCalendarWebPart
public class MyCalendarWebPart : Microsoft.SharePoint.WebPartPages.WebPart
private OWACalendarPart wpCalendar;
HtmlGenericControl litMsg = null;
HtmlGenericControl roundedCorner;

protected override void CreateChildControls()
wpCalendar = new OWACalendarPart();
litMsg = new HtmlGenericControl();
roundedCorner = new HtmlGenericControl();
roundedCorner.InnerHtml = “”;



private OWACalendarPart configureCalendar()
//Connect to the portal and get the portal context.
TopologyManager topology = new TopologyManager();
PortalSite portal = topology.PortalSites[new Uri(ConfigurationManager.AppSettings["SiteUrl"])];
PortalContext context = PortalApplication.GetContext(portal);

//initialize user profile config manager object
UserProfileManager profileManager = new UserProfileManager(context);
UserProfile profile = profileManager.GetUserProfile(true);

wpCalendar.Title = “My Calendar”;
wpCalendar.ViewName = “Weekly”;
wpCalendar.CssClass = “”;

// use the profile object to retrieve the properties you need in your company to
// retrieve the mail box name
string workmail = profile[PropertyConstants.WorkEmail].ToString();

wpCalendar.MailboxName = workmail;
wpCalendar.OWAServerAddressRoot = ConfigurationManager.AppSettings["ExchangeServerUrl"];

wpCalendar.Height = “655″;
wpCalendar.Width = “600″;
wpCalendar.ImportErrorMessage = “No EmailID found for your account.”;
litMsg.InnerHtml = “No EmailID found for your account.“;

return wpCalendar;

protected override void RenderWebPart(HtmlTextWriter output)
catch (Exception ex)

public override void RenderControl(HtmlTextWriter writer)

Note: In above code i am pulling site url and exchange server url from the appsettings of web.config of the site.


  1. Thanks for your detailed info on the issue. Can you please let me know exactly how you can deploy your solution.

  2. Hi Prasun,
    You need to know how to deploy a custom web part to SharePoint web part library before continue this post. You can find about it here.

    Let me know if you need any information on this.


  3. HI Praveen,
    Thanks for quick reply. I resolved this issue differently, I granted default "Author" permission. Added a new "Page Viewer web part" and then add a link pointing to http://servername/exchange/confroom1/calendar"

    No need to worry about Username/password, Works like a charm. Thanks.

  4. nice effort.. i like some original work

  5. The actual problem comes when you put OWAINbox and OWACalenderPart togather on the same page. The inbox web part take over OWACalender Part automatically. Do you have fix for that.

  6. With this approach, the display options/layout options are thrown to the wind and cannot be configured. A much better approach will be to derive a Calendar control from OWACalendarPart. Code is much simpler and you inherit all the flexibility offered by the OWACalendarPart control without any pains (ability to set the display options, layout etc). In this approach, all you need is an override for the CreateChildControls method where you can retrieve the current user's mail box name before calling base.CreateChildControls.