Tuesday, April 19, 2011

SP2010 : Feedback list

Scenario:
Client wanted a quick feedback link as a part of master page, so that end users can provide feedback. You can use the same idea to provide quick access to other lists.

Solution:
Here's list of things we needed to make this happen.
1. SharePoint list "Feedback" to hold all the feedback.

2. Dynamic link to add new item. We created a new WebControl [ Code below ]

Code:

using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;

namespace SKN
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:FeedbackLink runat=server></{0}:FeedbackLink>")]
public class FeedbackLink : WebControl
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}

set
{
ViewState["Text"] = value;
}
}

protected override void RenderContents(HtmlTextWriter output)
{
try
{
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists.TryGetList("Feedback");

if (null != list)
{
string aRender = "<a class='comment' id=idHomePageNewItem class=ms-addnew onclick='javascript:NewItem2(event, \"/_layouts/listform.aspx?PageType=8&ListId={0}&RootFolder=\");javascript:return false;' href=\"/_layouts/listform.aspx?PageType=8&ListId={0}&RootFolder=\" target=_self>Feedback</a>";
output.Write(string.Format(aRender, list.ID));
}
}
catch {
//handle exception here
}
}
}
}
3. Embedded this control in Master Page, that all.

0 comments: