Skip to main content

Free SharePoint Portal Server Web Part: Events for You


The Events for You Web Part functions in a manner very similar to the Links for You Web Part that can be found on the Home Page and Personal MySite page of SharePoint Portal Server. With this free Web Part, Event Items from the Events List located in the portal’s root web are presented to portal users based on their Audience membership. The Events for You Web Part can also be configured to override a user’s Audience membership, targeting Events to a definable set of one or more Audiences. In order to function properly, the Events for You Web Part requires that the Events List located in the portal’s root web be customized with the addition of an “Single line of text” type column named Audience. The Audience column can contain a semicolon delimitted list of Audiences for targeting that particular Event Item. The Events for You Web Part also requires that the Events List has the “Current Events” view.
Here’s a screenshot of Events For You in action:


Here’s a screenshot of Events For You in action:
E4U ShowOff
Setup Instructions
Follow these steps to setup your portal’s Events List for use with the Events for You Web Part:

Modify Events ListModify Settings and ColumnsAdd new column
1. Modify Events List2. Modify Settings and Columns3. Add a New Column
Single Line of Text Type ColumnPopulate Audience Column Values
4. Single Line of Text Column Type5. Poplulate Audience Values
Customizing Behavior
Once you have the Events list setup and populated with data, you can customize how the Events for You Web Part behaves:

Modify Shared Web PartDeselect 'Use default user audiences'Target Specific Audiences
1. Modify Shared Web Part2. Deselect ‘Use default user audiences’3. Target Specific Audiences


Technical Perspective: A few highlights
The Events for You Web Part makes use of the SPQuery object and CAML to query the Events list.
SPQuery query = null;
string caml = string.Empty;
SPListItemCollection results = null;

// CAML uses ISO8601 date format: yyyy-mm-ddThh:mm:ssZ
string todaysDate = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Today).ToString();
try
{
query = new SPQuery(events.Views["Current Events"]);
// Build the CAML Query to get all Events which belong to the current Audience (a)
// and have start date of today or in the future
// Apparently there is a problem with using CAML to get recurring events, so they're not supported.
// More info about DateRangesOverlap element at 
http://wss.collutions.com/Lists/FAQ/DispForm.aspx?ID=320
caml = string.Format("<Where><And><Contains><FieldRef Name='Audience'/><Value Type='Text'>{0}</Value></Contains>"
+ "<And><Geq><FieldRef Name='EventDate' /><Value Type='DateTime'>{1}</Value></Geq><DateRangesOverlap>"
+ "<FieldRef Name='EventDate'></FieldRef><FieldRef Name='EndDate'></FieldRef><FieldRef Name='RecurrenceID'>"
+ "</FieldRef><Value Type='DateTime'><Month/></Value></DateRangesOverlap></And></And></Where><OrderBy><FieldRef Name='EventDate'/></OrderBy>",

audienceName, todaysDate);
query.Query = caml;
results = events.GetItems(query);
// If the results collection contains items, we have some hits
if(results.Count > 0)
hasEvents = true;
}
catch(ArgumentException ex)
{
// 'Current Events' View doesn't exist
_messages.Text += "<p>This portal's 'Events' List must have a 'Current Events' View defined in order for this web part to function properly.</p>";
_hasHandledErrors = true;
break;
}
catch(NullReferenceException ex)
{
// No items in results collection
_hasHandledErrors = true;
break;
}
catch(Microsoft.SharePoint.SPException ex)
{
// 'Audiences' column not defined
_messages.Text += "<p>This portal's 'Events' List must have a 'Single line of text' type Column named 'Audience' defined in order for this web part to function properly.</p>";
_hasHandledErrors = true;
break;
}
The AudienceManager object is used to determine Audiences for the current user:
// Returns an array of audience names for the current portal user
public static string[] GetUserAudiencesNamesArray(string url)
{
// Get the portal contextSPSite portal = new SPSite(url);
PortalContext context = PortalApplication.GetContext(portal.ID);

// Get the list of audiences for the user
AudienceManager manager = new AudienceManager(context);
string[] names = new string[manager.GetUserAudienceIDs().Count];
IEnumerator enumer = manager.GetUserAudienceIDs().GetEnumerator();
int i = 0;
while(enumer.MoveNext())
{
AudienceNameID temp = (AudienceNameID)enumer.Current;
names[i] = temp.AudienceName;
i++;
}
return names;
}
The MSOPGrid_doBuilder() JavaScript function located in ows.js is used to launched the Audience Chooser Custom Property Builder:
private void RegisterJavaScripts()
{
try
{
// Client-side code to apply changes
string applyFunction = "ApplyProperties" + _qualifier;
string EmbeddedScriptFormat = "<script language=jscript>function " + applyFunction + "(){\n";
EmbeddedScriptFormat += "document.forms[MSOWebPartPageFormName].MSOTlPn_Button.value = 'apply';\n";
EmbeddedScriptFormat += "document.forms[MSOWebPartPageFormName].elements['" + _shortId + ":MSOTlPn_AppBtn'].click();\n";
EmbeddedScriptFormat += "}\n";
EmbeddedScriptFormat += "</script>\n";
if(!Page.IsClientScriptBlockRegistered(applyFunction))
Page.RegisterClientScriptBlock(applyFunction, EmbeddedScriptFormat);
// Client-side button click handlerstring onClick = "MSOPGrid_doBuilder('"
+ "_layouts/1033/Audience_Chooser.aspx" + "', " + "EventsForYou" + _qualifier
+ ", '" + "dialogHeight:510px;dialogWidth:560px;help:no;status:no;resizable:yes" + "');";
onClick += applyFunction + "();";
_button.Attributes.Add("OnClick", onClick);
// Client-side checkbox click handler_chkDefaults.Attributes.Add("OnClick", applyFunction + "()");
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(string.Format("{0} {1} {2}",ex.GetType().ToString(), ex.Message, ex.StackTrace), "ERROR");
}
}
The source code and binaries for the Events for You Web Parts are released to public domain. Download source and binaries from the links below.

Comments

Post a Comment

Popular posts from this blog

Tab Control in Asp.Net

Scenerio: I need your help in designing tab control in   asp.net .My requirement is I need a tab control in   asp.net (C#) like  for example goto my computer ,right click c drive and select properties.we get tabs like general,security etc....... like that i need to design one tab control(no need of any rightclick) in my web page and the database table columns should come as tabs and inseide the tab data of that particular column should come.   Example:Employee master tab1:Employee name.........his name in the tab tab2:Age.............his age tab3:Address........his address   Solution:   You can do this using a simple div <style type="text/css"> .tabs         {             position: relative;             height: 20px;             margin: 0;   ...

AI and Microsoft: Revolutionizing Efficiency in Nonprofit Organizations

  How AI and Microsoft Enhance Efficiency in Nonprofit Organizations In today’s fast-paced world, nonprofit organizations face unique challenges—limited resources, increasing demands, and the constant need to do more with less. But what if technology could be the game-changer they need? In my latest research paper,  "How AI and Microsoft Enhance Efficiency in Nonprofit Organizations" , I explore how cutting-edge technologies like Artificial Intelligence (AI) and Microsoft’s innovative tools are revolutionizing the way nonprofits operate. From streamlining administrative tasks to enhancing donor engagement and optimizing resource allocation, AI and Microsoft’s solutions are empowering nonprofits to focus on what truly matters—their mission. This paper dives deep into real-world examples, practical applications, and the transformative potential of these technologies. Whether you’re a nonprofit professional, a tech enthusiast, or simply curious about the intersection of technolo...

Social tagging overview in Sharepoint 2010

A tag is a word or phrase that identifies an individual piece of information according to a set of attributes or criteria. Tags make it easy to find and share information about a specific subject or task. Social tagging helps users categorize information in ways that are meaningful to them. Social tagging can improve the quality of search results by filtering against specific tags, and it can also connect individuals who want to share information with other users who have like interests. This article describes the social tagging features in Microsoft SharePoint Server 2010. This article does not describe how to configure social tagging features. It also does not discuss how to implement social tagging features as part of an overall social media strategy for an enterprise. About using social tagging features Social tagging features help users to share information and to retrieve relevant, high-quality content more efficiently. Such sharing encourages collaboration and b...