Today's Birthdays
Hey folks,
How would I go about creating a webpart (some sort of content-query for people, I presume) which would show me all SharePoint users whose birthday is today?
We're using MOSS 2007, so we already have "Birthday" as a profile that can be filled out by each user.
I don't even know where to start. The "Content Query" webpart doesn't even seem to allow people/users as one of its content types.
Cheers,
Matt
ps. Also, our MOSS implementation doesn't seem to be able to search for people based on birthdays. The birthday, when entered, is a clickable link on someone's profile page, and leads to a search for Birthday:"March 22" (for example). This, however, returns no results (despite the fact that you've just come from someone with that birthday).
Can someone else verify whether searching based on Birthday works?
[883 byte] By [
mabster] at [2008-1-2]
Anybody got any ideas on this?
I'm especially interested in why we can't search for birthdays. It lets me click on someone's birthday from their profile page but the search results are empty.
Ok! I think I'm getting somewhere in finding the cause of this problem.
On my profile page, my birthday is displayed as "March 22". It's a link, and when I click on it, it starts a People Search with this query:
Code Snippet
Birthday:"March 22"
This finds no results.
However, if I change the people search query to this:
Code Snippet
Birthday:"22 March"
... it finds me!
So it seems that the profile page has a different date format to the search index.
The server itself has "English (Australia)" across the board. Where else can I look? Or is it not a locale-related problem? Anybody?
Cheers,
Matt
Did you get things to work?
If not how far did you go/get...
What webparts did you use etc?
Nah, never got anywhere with the idea of a "today's birthdays" web part. Shame, because I think it'd be a popular web part on a lot of people's MOSS sites.
Hi,
Im working on a web part to display birthdays of employees at my work. It might give you some inspiration. The code looks somthing like this:
using
System; using
System.Runtime.InteropServices; using
System.Web.UI; using
System.Web.UI.WebControls.WebParts; using
System.Web.UI.WebControls; using
System.Xml.Serialization; using
System.ComponentModel; using
System.Data; using
System.Data.SqlClient; using
System.Collections; using
System.Drawing; using
Microsoft.SharePoint; using
Microsoft.SharePoint.WebControls; using
Microsoft.SharePoint.WebPartPages; namespace
Birthdays {
[
Guid("6643ddb9-12a9-426f-b233-1216883ce039")] public class Birthdays : System.Web.UI.WebControls.WebParts.WebPart {
private DataGrid _grid; public enum DisplayType {BeforeAndAfter, TodayAndAfter, TodayOnly}; DisplayType _display = DisplayType.TodayAndAfter; [
WebBrowsable(true), Personalizable(true), Category("Miscellaneous"), DisplayName("Display"), WebDisplayName("Display"), WebDescription("Which birthdays should be displayed?"), WebPartStorageAttribute(Storage.Personal), DefaultValue(Birthdays.DisplayType.TodayAndAfter) ]
public DisplayType Displaying {
get {return _display;} set {_display = value;} }
bool _stretch = true; [
WebBrowsable(true), Personalizable(true), Category("Miscellaneous"), DisplayName("Stretch"), WebDisplayName("Stretch"), WebDescription("If checked, the webpart will render with full available width."), WebPartStorage(Storage.Personal), DefaultValue(true) ]
public bool Stretch {
get {return _stretch;} set {_stretch = value;} }
public Birthdays() {
this.ExportMode = WebPartExportMode.All; }
protected override void OnLoad(EventArgs e) {
base.OnLoad(e); DataTable dt = CreateList(); }
protected override void CreateChildControls() {
base.CreateChildControls(); _grid =
new DataGrid(); _grid.AutoGenerateColumns =
false; _grid.Width =
Unit.Percentage(100); _grid.GridLines =
GridLines.Horizontal; _grid.BorderWidth =
new Unit("0px"); //Birthday BoundColumn birth = new BoundColumn(); birth.ItemStyle.HorizontalAlign =
HorizontalAlign.Left; birth.DataField =
"Birthday"; birth.DataFormatString =
"{0: dd-MMM}"; _grid.Columns.Add(birth);
///Employee HyperLinkColumn employee = new HyperLinkColumn(); employee.ItemStyle.HorizontalAlign =
HorizontalAlign.Left; employee.DataNavigateUrlField =
"Name"; employee.DataTextField =
"Name"; //Redirect to Public MySite //employee.DataNavigateUrlFormatString = HttpContext.Current.Request.Url.LocalPath /*+ "?Title_ID={0}"*/; _grid.Columns.Add(employee);
//Years BoundColumn year = new BoundColumn(); year.ItemStyle.HorizontalAlign =
HorizontalAlign.Right; year.DataField =
"Years"; year.DataFormatString =
"{0} years"; _grid.Columns.Add(year);
this.Controls.Add(_grid); }
public DataTable BirthdayTable() {
DataTable dt = new DataTable(); dt.BeginInit();
//Birthday DataColumn birthday = new DataColumn(); birthday.DataType = System.
Type.GetType("System.DateTime"); birthday.ColumnName =
"Birthday"; dt.Columns.Add(birthday);
//Name DataColumn name = new DataColumn(); name.DataType = System.
Type.GetType("System.String"); name.ColumnName =
"Name"; dt.Columns.Add(name);
//Years DataColumn year = new DataColumn(); year.DataType = System.
Type.GetType("System.Int32"); year.ColumnName =
"Years"; dt.Columns.Add(year);
dt.EndInit();
dt.BeginLoadData();
string connectionString = "<censored>"; using (SqlConnection connection = new SqlConnection(connectionString)) {
try {
connection.Open();
using (SqlCommand cmd = connection.CreateCommand()) {
cmd.CommandType =
CommandType.Text; cmd.CommandText =
"SELECT <Columns> FROM <Table> ORDER BY MONTH(<DateTime column containing ppl's b-day>), DAY(<DateTime column containing ppl's b-day>)"; SqlDataAdapter adapter = new SqlDataAdapter(cmd); adapter.Fill(dt);
}
}
catch (Exception ex) {
Label _lblError = new Label(); _lblError.Text = ex.Message +
" " + ex.StackTrace; this.Controls.Add(_lblError); }
finally {
connection.Close();
}
}
dt.EndLoadData();
dt.AcceptChanges();
return dt; }
protected DataTable CreateList() {
DataTable dt = ViewState["dtBirthday"] as DataTable; if (dt == null) {
dt = BirthdayTable();
ViewState[
"dtBirthday"] = dt; }
return dt; }
protected override void OnPreRender(EventArgs e) {
base.OnPreRender(e); DataTable dt = CreateList(); bool color = false; foreach (DataRow row in dt.Rows) {
if (color == false) {
_grid.AlternatingItemStyle.BackColor =
Color.White; color =
true; }
else {
_grid.AlternatingItemStyle.BackColor = System.Drawing.
Color.FromName("#DCE3EB"); color =
false; }
}
DateTime cutdate = DateTime.Now; /* if (cutdate.Month == dt.Colums.month)
{
if (cutdate.Day == dt.Colums.day)
{
_grid.Font.Bold = true;
}
}
else
{
_grid.Font.Bold = false;
}*/
try {
EnsureChildControls();
int idx = 0; foreach
(DataRow row in dt.Rows) {
DateTime birth = Convert.ToDateTime(row["Birthday"]); DateTime birthCY = new DateTime(cutdate.Year, birth.Month, birth.Day); TimeSpan spantobirth = cutdate.Subtract(birthCY); double daystobirth = spantobirth.TotalDays; bool ismarked = false; switch(_display) {
case DisplayType.TodayOnly: if (daystobirth > -1 && daystobirth <= 0) {
ismarked =
true; }
break; case DisplayType.BeforeAndAfter: if (daystobirth > -8 && daystobirth < 8) {
ismarked =
true; }
break; case DisplayType.TodayAndAfter: default: if (daystobirth > -1 && daystobirth < 8) {
ismarked =
true; }
break; }
if ((cutdate.Year - birth.Year) > 99) {
ismarked =
false; }
}
} catch (Exception ex) {
Label _lblError = new Label(); _lblError.Text = ex.Message +
" " + ex.StackTrace; this.Controls.Add(_lblError); }
_grid.DataSource = dt;
_grid.DataBind();
_grid.Visible =
true; }
protected override void Render(HtmlTextWriter writer) {
base.Render(writer); }
}
}
I hope this will help you, eventhough it's still under development 
Hi,
I've done this WebPart for one of the clients, what you'd need to do is to access the SharePoint Profile Database and loop through the user profile's Birthday to check if the day and month of each user is the same as today's and if they are the same as today you return those users or user. Display the users such that if you click on the user, it suppose to take you to their profile. Put that in a Panel so that if there's no person who's birthday is today the webpart can close itself and reappear if there are birthdays.
You can use the following code to access the SharePoint Profile Database.
private static UserProfileManager getProfileManager(){
ServerContext context = ServerContext.Current;
UserProfileManager profileManager = new UserProfileManager(context);
return profileManager
}
private static UserProfile getUserProfile(string thename){
ServerContext context = ServerContext.Current;
UserProfileManager profileManager = new UserProfileManager(context);
return (profileManager.GetUserProfile(thename));
}
Hey, could you tell me where the user profile list is located? Im guessing in the root folder of the site http://sharepoint

ort/? But i cant acces this location because of the administrator didnt gave me permission.
If you could tell me where it is located the administrator can give me acces.
Thnx in advange,
Rick
How you doing?
User Profiles are part of the SharePoint Central Administration, you'll need access to that. If you are using MOSS 2007 you can go to your start -> all programs -> Microsoft Office Server -> SharePoint 3.0 Central Administration in the server or else ask for access to the SharePoint Central Administrator site. Your administrator can follow the steps above directly in the server where SharePoint is installed.
In Shared Services Administration, click on User Profiles and Properties under User Profiles and My Sites.
Hope that helps.
Thank you for your help.
The user profiles are being made when the mysite of a user gets activated and after that the user have to fill in its own birthday right?
This would mean we would have to ask everyone to make a mysite and fill in his birthday and other details wich ofcourse would be perfect but prolly wont happen. Therefor we found another solution and we made a calendar. We filled this calendar with all the birthdays and made them reocur every year. So now we have the calendar(read database) and we made a dataviewwebpart where we took the data out of the calendar and made a couple of custom columns to calculate the days to post the birthday on the sharepoint site.
So now we have the birthdays shown three days before the actuall birthday date and the message will disappear 3 days after the actuall birthday date.
Hope this could be of some help for people.