Friday, June 22, 2007

FeedBack Webpart

Feedback web part
Published 07 June 07 10:17 PM | jannemattila

A while back I got a question that how would I solve "feedback feature request" for my customers case (platform was MOSS 2007). Idea is that from every page of the portal you could go and give feedback. And if you do give feedback it would be important to know that what was the page that "initiated" the feedback for the user. And even more... if that page has page contact set then feedback would be automatically sent to the contact. Of course the feedback form should look a bit different dependending of the site where user decided to give feedback. Normally there would be a lot of possibilities to solve this kind of "feature request", but if you combine all the above... I'll only got one good solution so it's easy to choose what to write about this time :-)
My solution (if you have better then let me know!)

So I decided to solve this by creating a web part. Web part could then host feedback form and have logic for the rest of the requirements. But in order to have easily changeable feedback form I thought that this web part could host user control that actually is the user interface (UI) for the form. And web part could runtime select the right form to use. So next I thought that I need to have some custom code to get the page contact from previous page and other handling code too. I didn't want to add code to the UI element since I needed to support multiple feedback forms. And if those forms are different from each other it would mean that I would need to get the values in runtime. Before going to the Visual Studio I decided to create small checklist:

* Multiple feedback form UIs
o No code to the UI!!!
o Seperate the code and UI
* Form should be easily changeable runtime
o Decision making can't be restricted in any way and the solution could come from...
+ web part properties
+ users profile
+ site properties / some data from site
+ ...
* Feedback should know the page that initiated the call

With that list I was ready to go! Of course I did the normal look up using search engines and found nice article that has something that I could use. It was User Control Container Web Part and it was about "SmartPart" which is web part that hosts user controls. So the basic groundwork was already set and I just started to work on the other features.

I used the Visual Studio extensions for WSS 3.0 and created new web part project. In just few clicks I had my project ready for testing. Here is the code I managed to do:



using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Web.UI.WebControls;
using System.Text;
using Microsoft.SharePoint.Publishing;
using Microsoft.SharePoint.Utilities;

namespace Feedback_Web_Part
{
[Guid("f7bf59d1-f2be-4361-8a3e-f4604875fbcc")]
public class Feedback_Web_Part : System.Web.UI.WebControls.WebParts.WebPart
{
// TODO: add property so that user can change the feedback form:
String feedbackFormUrl = "/_controltemplates/Feedback.ascx";
Control feedbackForm = null;
HiddenField feedbackLocationUrl = null;

public Feedback_Web_Part()
{

}

protected override void CreateChildControls()
{
Controls.Clear();
base.CreateChildControls();
this.ChildControlsCreated = true;

feedbackLocationUrl = new HiddenField();
if (this.Page.IsPostBack == false)
{
feedbackLocationUrl.Value = this.Page.Request.ServerVariables["HTTP_REFERER"];
}
this.Controls.Add(feedbackLocationUrl);

try
{
feedbackForm = this.Page.LoadControl(feedbackFormUrl);
Button sendButton = feedbackForm.FindControl("SendFeedbackButton") as Button;
if (sendButton != null)
{
sendButton.Click += new EventHandler(sendButton_Click);
}
}
catch (System.Exception ex)
{
feedbackForm = new LiteralControl("Couldn't load '" +
feedbackFormUrl + "'! Error message: " + ex.Message);
}

if (feedbackForm != null)
{
// Add to the Controls collection to support postback
this.Controls.Add(feedbackForm);
}
}

protected override void Render(HtmlTextWriter writer)
{
this.EnsureChildControls();
this.RenderChildren(writer);

if (feedbackForm.Visible == false)
{
// User has already submitted feedback:
writer.Write("Thank you for your feedback!");
}
}

void sendButton_Click(object sender, EventArgs e)
{
StringBuilder feedback = new StringBuilder(1024);
if (feedbackForm != null)
{
foreach (Control control in feedbackForm.Controls)
{
if (control is TextBox)
{
TextBox textBox = control as TextBox;
feedback.Append(textBox.ID.Replace("_", " ") + ": ");
feedback.Append(textBox.Text);
feedback.Append(Environment.NewLine + "
");
}
else if (control is DropDownList)
{
DropDownList dropdown = control as DropDownList;
feedback.Append(dropdown.ID.Replace("_", " ") + ": ");
feedback.Append(dropdown.SelectedValue);
feedback.Append(Environment.NewLine + "
");
}
else if (control is CheckBoxList)
{
CheckBoxList checkBoxList = control as CheckBoxList;
feedback.Append(checkBoxList.ID.Replace("_", " ") + ":
");
foreach (ListItem item in checkBoxList.Items)
{
if (item.Selected == true)
{
feedback.Append(item.Text + " ");
}
}
feedback.Append("
");
}
}
}

String referer = feedbackLocationUrl.Value;
if (String.IsNullOrEmpty(referer) == false)
{
using (SPSite site = new SPSite(referer))
{
using (SPWeb web = site.OpenWeb("/"))
{
SPListItem item = web.GetListItem(referer);
if (item != null)
{
if (PublishingPage.IsPublishingPage(item) == true)
{
PublishingPage publishingPage = PublishingPage.GetPublishingPage(item);
// TODO: send email to local contact if set
// => publishingPage.LocalContactEmail
// OR
// TODO: send email to contact if set
// => publishingPage.Contact
// OR whatever you like :-)
SPListItem feedbackListItem = web.Lists["Feedback"].Items.Add();
feedbackListItem[SPBuiltInFieldId.Title] = "Feedback from " + referer;
feedbackListItem[SPBuiltInFieldId.AssignedTo] = publishingPage.Contact;
feedbackListItem[SPBuiltInFieldId.Body] = feedback;
feedbackListItem.Update();

feedbackForm.Visible = false;
}
}
}
}
}
}
}
}

And that code needs also Feedback.ascx to work:

You probably noticed that there isn't anything special about that user control. Only IDs of the controls have some special meaning. I highlighted "Send" buttons ID SendFeedbackButton because it's searched from my code (on line 46). Other IDs are used when data is pulled from the form to the feedback that is stored to the SharePoint task list. Between lines 82 and 111 I'll loop the controls and dynamically get the values to the feedback. And in order to make the feedback look more nice I'll replace underscores to spaces. You can see underscore in Feedback.ascx on line 7.
Feedback form in action

Well for the person who wants to give feedback the form looks like this (and again... just to remind you... I'm not UI designer :-):

And when user presses the Send-button the form renders like this:

So this is probably good place to explain the code on lines 36 - 41. It's used to store the HTTP_REFERER information to the page. Because if you don't store it and user presses the Send-key... you'll get the current page as referer and most likely that isn't what you want.

As always my code is fast and furious (maybe too fast sometimes?) and you should take it as example but fix all the problems that I'm ignoring :-) Like in your implementation you might want to use web part properties to control the usercontrol form. It's easy... just create property and remember to add [WebBrowsable(true)] on it. Then you're good to go.

Another important thing that I just "skipped"... is the user rights (if you DIDN'T notice it while reading the code... shame on you!!!). I just created that demo to run with the same user and that isn't probably what you want. You want probably to run that "Save" code in some other user account. For that you can use the following code:

1
2
3
4
5
6
7
8
9
10



SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPControl.GetContextSite(HttpContext.Current).ID))
{
using (SPWeb web = site.OpenWeb("/"))
{
// TODO: put the magic here!
}
}
});

Feedback for the page contact

From code you can easily see that the task is created and it's assigned to the page contact. Here the email the page contact gets:

And if user clicks to see the item in SharePoint:

So it's pretty obvious for the page contact that he/she has received feedback regarding the page http://demo1/Pages/Main.aspx.
This could be also used for...

...sharing functionality with SharePoint apps and ASP.NET apps!

My title is kind of self describing :-) But if you want to have code that can be used in ordinary ASP.NET applications and have that same functionality in SharePoint too... well using the above methods it would be quite easily achievable. Just create web part that hosts you user controls that do some fancy stuff like get data from backend systems or whatever you need. Just keep in mind when creating the controls that it could be hosted in different kind of environments.

It think that this story has been told. Maybe next time something out of the SharePoint circle :-)

Anyways... happy hacking!

J
Filed under: Microsoft Office SharePoint Server 2007, Programming
Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS
Comments

# Michell Cronberg - Feedback web part said on June 7, 2007 3:28 PM:

PingBack from http://blog.cronberg.dk/PermaLink,guid,09a4e46c-b953-485c-b0da-51688be8c9b2.aspx

PublishingPage Url Question

PublishingPage Url Question
Sharepoint
PublishingPage Url Question

Url Reference: http://www.developerfood.com/publishingpage-url-question/microsoft-public-sharepoint-portalserver/be9f4441-b6c7-4e6c-a769-c47b7bfd1ea0/article.aspx

Hi,


What's the purpose of the PublishingPage Url property?


I have some sample code like the code below:
PublishingPage pubPage;
// ...init pub page...
string title = pubPage.Title;
string navURL = pubPage.Url;


When I use this code, the URL for one particular page on my site looks like
this:
http://mycomputer_catalogs/masterpage/Pages/Governor.aspx
It's the same if I use pubPage.Name. The returned value doesn't seem to be
valid.


If I use pubPage.Uri.ToString(), I get a valid url:
http://mycomputer/RC/letter/2007/01/Pages/Governor.aspx


Thanks,
Steve


--
My BizTalk blog:
http://stevestechnotes.blogspot.com/


Lizard.That.Was@hot.mail.com
Thursday, April 19, 2007 at 5:33:56 PM
(64 days, 2 hours, 55 minutes ago)
Sharepoint

Please also consider these articles

Unable to read data from the transport connection: An existing connection was forcibly closed
Hi there, I am REALLY stuck on this one and would appreciate any help or direction. I'm not sure if this is a Sharepoint or an Analysis Services problem... I am trying to use the Analysis Services Filter. I choose an ODC that I created in Excel 2007 and uploaded to the Data Connection Library.


MOSS 2007 Value does not fall within the expected range
When checking out documents in a document library I get the following error:Value does not fall within the expected range. The fix for now is to click on the "Go Back to Site" link that is displayed on the page and then go back to the document library and then it lets me check the document out


How To Filter Content Query WebPart based on Custom Site Column
I have created a custom site column (boolean), assigned it to a content type, and created a couple of new pages based on that content type. I have set the boolean field to Yes for one, and No for the other. I next added a Content Query WebPart to a page and it displays both pages correctly. Nex


Re: Event id 27745 (Could not connect to config DB) in MOSS 2007 - what to do?
You are not alone, we get them too. We have have a five server farm but it too is showing up. We were thinking we have network problems, but now I am not sure after reading your message. I will post again if we find out anything. "MartinNr5" wrote in message news:117447


Re: Eventid 202 Src: Sharepoint Portal Administrative Service, Synchronization Exception Occurred Help?
I have the same problem In event log I filled of this Even, and every 30 sec What should we do? Thanks in advance "markm75" wrote in message news:1172590039.099404.76970@k78g2000cwa.googlegroups.com... > I've searched around on this error, but cant find a real fix for this > o


Search error in MOSS 2007
I have set up several farms and not had this problem, however, on one deployment, I am seeing something like this as well. The crawl logs show that content is being crawled, however, whenever a user searches for anything through the SharePoint UI, they get "Your search cannot be completed


Error 6482 Excel.Server path specified cannot be used at this time
I have MOSS 2007 Enterrprise RTM installed and running. After a few days I get the following error message in the event log every 30 seconds. If I reboot the server, I don't get the error message for a few more days. Where can I find the incorrectly specified path? Event Type: Error Event Source:


SharePoint.Upgrade.SPUpgradeException :Duplicate Id on sequence
Hello. I am trying to upgrade from Microsoft Office SharePoint Portal Server 2003 to 2007. Prescan tool comes with no errors and I am NOT running on a farm. At the step 2 of the Sharepoint Configuration wizzard I get an error like : Event Type: Error Event Source: SharePoint Products and Technol


Re: upgrade MOSS2007 B2TR to RTM
Hello Russ, Check your SPTImer and make sure it is set to the proper service account. Check your event logs also for any events and post them back. I recently upgraded a large farm to RTM from B2TR and on box failed at the same point over and over.... ran for hours and never got past task 8 of


Attempted to read or write protected memory error
I have installed 2 physical Windows 2003 x64 standard server. One server with MSSQL Server 2005 x64 standard, the other with MOSS 2007 64bit enterprise. Both server have current patch level. After a server reboot, both server are operating without error for about 2 hours. Then, the windows event


RE: Moss 2007 - Unable to view feeds in RSS Viewer
Does anyone have a fix for this? We have the same problem - external RSS feeds work, but we can't display any Sharepoint RSS feeds with the webpart. We are using MOSS 2007 RTM, with a basic install. The error we get is: Exception in RssAggregatorWebPart::OnPreRender... System.Collections.Gene


Re: Sharepoint designer Server Error: Access Denied
hi possibly the user is not present in site collection administrator list. Site Actions -> Site settings -> Modify All Site S ettings In User and Permissions -> Site Collection administrator click add user. Hope it will helpful. Thanks EggHeadCafe.com - .NET Developer Portal of Choice ht


Error Msg: Not in configuration Database
Hi All, I have few departmental sites they were working fine but suddenly I see one dept. site with an error when I click this site link. The error message is ???The Web site that is referenced here is not in the configuration database.??? How do I fix this and how to know and trace who is resp


How to remove "View All Site Content" for some user groups
Hi all, is it possible to remove "View All Site Content" (upper left) within sharepoint 2007 for some users groups, for example: members and readers, but not Admins ?? Thank you in advance


SSO Error: You do not have the rights to perform this operation.
I get the error : You do not have the rights to perform this operation. When i tried to create the SSO database. The problem i see is that it??s using old credentials from a previous user and not accepting the new credentials i??m declaring. I get error: 1038 (an old username is display on the


Backup and restore problem for MOSS 2007
For the backup and restore process, I have done the backup process (Production server) and would like to restore that backuped folder in the another server (Test server). It is shown the Access to the path \\servername\path\spbrtoc.xml is denied even through that path assigned the sharing property


Re: MOSS 2007 Collection consolidation w/stsadm export: "User cannot be found"
I am having some of the same errors (we did the same migration). Did you ever find out a cause? "BubbleG" wrote in message news:1166735098.795790.76850@f1g2000cwa.googlegroups.com... > I've migrated my SPS2003 Portal to MOSS 2007 Enterprise Trial version > successfu


Re: Using SQL express with WSS 3.0
Josh, In terms of upgrading to SQL 2005 i'm not sure you can. I have however, moved the content database from SSEE (WID) to SQL 2005. I used STSADM to create a DAT file backup of all sites. C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\STSADM.EXE" -o backup -url ht


Error Event 7888
Hi, I setup a moss 2007 system with one web server and one SQL 2005 server. It works fine. But in web server event viewer, MOSS report an error every minute. Below are the error details. Source: Office SharePoint Server Category Office Server General Event: 7888 A runtime exception was detected.


SharePoint 2007 Document Library Explorer View on IE7 in Vista
Greetings, I've noticed that SharePoint 2007 Explorer View for document libraries does not work with Internet Explorer 7 in Vista. There is a page that comes up (res://ieframe.dll/nowebfolder.htm) that says: This folder cannot be opened in Internet Explorer You can view this folder in Windows Expl


HRESULT: 0x80020009
Hi, when anyone tries to go to their MySite they get an error. The error is ???Exception occurred. (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))???. We are running MOSS2007 on SQL2005Std, backend Apps Server and one Web Front End. Has anyone seen this problem before? Thanks Phil


Unable to add selected web part (OWA)
We are trying to add the Outlook Web Access webparts to our SharePoint Server 2007 portal, but with no luck. When we try to add som parts (inbox, calendar, contacts, etc) we only get this error message: Unable to add selected web part(s). My Inbox: Value cannot be null. Parameter name: serverCon


Security and SiteProvisioning.cs
I'm trying to create a new RoleDefinition when the site is created in the SiteProvisioning.cs file at the bottom is a copy of the code that I'm using, basically the group has all of the rights as a Contributor except for deleting. The ideaHopperList variable below is a reference to a


MOSS 2007 Hourly Profile Synch
Hello everyone, Were looking to customize the SSP Profile import configuration The only time configuration we can set for the incremental synch of user profile is on a daily or weekly basis in the SSP I would like to run a script either stsadm or anything to run an incremental synch t


Network share as a document library - Sharepoint Server 2007
Is it possible to make a Document Library out of a shared folder on another server? One possible is example: Having a user's home folder accessible as a document library on our Sharepoint site. Thank you


custom list entry add an entry to calender
hi all, at the moment i got the following problem that i got a custom list where i can add some tasks. is it possible to automatically add a calender entry based on the task definition? example: you got a inventory where your warranty will end. directly when i add a new pc i also want to add th


Sharepoint 2007 Backup error
I am getting the error message trying to backup sharepoint 2007 sites. Any ideas? BackupDiskFile::CreateMedia: Backup device 'c:\files\spbr0003\00000020.bak' failed to create. Operating system error 3(The system cannot find the path specified.). For more information, see Help and Support Center


Re: Custom Navigation Question
In order to stay compatible with WCM (MOSS) navigation, you'll need to subclass the PortalSiteMapProvider, not SiteMapProvider. The corresponding data source class to subclass is PortalSiteMapDataSource. You can get improved error reporting by making the following changes in web.config: Look fo


Re: How do I add external users?
Specify them as users on the SharePoint server. Give them permanent passwords when you do. Then create them using \ (myserver\Fred) (Note the security issues because of the permanent password, but these users don't have access to the SP srver so can't change their passwor


How to Oraginazation Hierarchy
Hello I like to create an Organization Hierarchy and like to display in tree view format. let me know if any one can help me in this matter. Ashish


Deleting Navigation Items
We are having lots of problems deleting navigation items. I am getting messages like: "The page has been modified by another author" And also previously it would seem to save (when deleting an extra header) but then it would never actually remove it... This seems very buggy to me. Project Serve


Error configuring Indexing Sever
Hi, We are installing a medium MOSS 2007 Enterprise farm and when attempting to configure the indexing server a failure occurs. When checking the event log we get the following error "The path for the index location is not valid." When running the initial setup we changed the path of the Data


Backup MOSS 2007 SQL light and restore
I have a MOSS 2007 server running the SQL light. I am practicing backing it up and then restoring it to another server and using SQL 2005. Backup worked, Setup of MOSS using SQL 2005 worked. Now that it is done I try the restore and get two errors. The first one has to do with the site. "fai


Strange postUpgrade issues
Hi all, Just made an in-place upgrade from 2003 to 2007 rtm, all went ok... but I have some issues for example: Some sites have links like that: http://sharepoint/Topics/Proc/Pages/UpgLandingPgRedir.aspx I click and I'm getting page saying ************* This page is redirecting to http://sharep


Configure Search and Indexing: problems
Searching in SPS 2003 doesn???t work. In ???Configure Search and Indexing??? section there are errors, for example: 3/1/2007 5:10:00 PM Modify http://fondoweb:81/ The address could not be found, (0x80042616 - Error in the Site Data Web Service. ) 3/1/2007 5:10:00 PM Modify sps://fondoweb:81/


"Content xxx type not found in web" error - Portal Server 2007
We have a new portal server installation that is working fine except for one strange error. We created our new site using the "Publishing Site" template and also created subsites below it. All that went fine. However, if we try to create a new page ("Create Page" command from the "Site Actions


server error in '/' Application
i am using sharepoint 2003, i cannot access any of mine previously created website the below error message is displayed, although i can create top level websites, but after picking up the template the website gets created, but when i click the newly created website url i just get this error, Th


upgrade MOSS2007 B2TR to RTM
I'm having a problem doing the upgrade to RTM. I'm stuck on the config wizard on task 8 of 9. I've left it run over 30 minutes, rebooted restarted the wizard to no help. My Sharepoint server is on 1 server with SQL running on another server with SQL 2000 SP3a Here is my upgrade log.. [S


Event 3, New search server found...?
I have SPS 2003 SP2 installed on a single machine. Fie to six times a day the event log shows a message like this: Sharepoint Portal Server Event ID: 3 "a new search server was found or added". The server name is always the computer on which SPS is running. I am sure that nobody plays with the


Search and System Policy
Just upgraded from B2 to B2TR. The search is failing to activate from central administration with the error message "An unhandled exception occurred in the user interface.Exception Information: System policies must have Full Control". Additional messages refering to system policy permissions are


Problems with Scheduling an index/crawl job, MOSS2007
Hi, I'm trying to create a schedule for "Local Office SharePoint Server sites" content source. I'm in the "Edit Content Source" window, and is pushing the "Create schedule" link. A new window appears where I can set a schedule for updating the index. When pushing OK, the message "Access is deni


Re: Error:sps3://Servername
In article <2006113073726arvindk@intelligroup.com>, wrote: > Did you manage to fix this issue? If yes then please let me know how to go about it. My people search is not working. > Yes, he did. He uninstalled .Net 2.0 . -- Hollis Paul Mukilteo, WA USA


SPS 2003 Error
When creating a portal, I get the following error. i searched and search but no luck on a resolution. Please help!! 13:16:25 Portal creation job exception. (status=PortalAdminJobStatusFailed) System.Runtime.InteropServices.COMException (0x80005006): Exception from HRESULT: 0x80005006. at Syste


error Unable to connect to SQL Server session database
Hello, I installed 2 virtual machines: Server A: Windows 2003, SQL Server 2005 SP1 Server B: Windows 2003, MOSS 2007 in spanish I'm using Windows Authentication to connecto to the Database, and they are in the company's domain. I created a Publishing Portal, to create a portal. I was trying to


Search failing saying "Missing Connection String"
Greetings, Just updated from Moss 2007 B2 to B2TR. When executing a search from a front end site it is failing with a services level message and review of the event viewer shows the following: "Could not create a database session. Context: Application 'ffe2a634-1a04-4393-b68a-6ae4d71c2654' Det


Excel Services Drillthrough
Is there a way to implement drillthrough with Excel Services? For example, say I have an Excel Web Access web part connected to an SSAS cube in one page and a second Excel Web Access web part in another page (or even on the same page). I would like when the user clicks something in the first web


Troubleshooting: "Not enough storage is available to process this command."
All, I am troubleshooting Event Log Errors related to MOSS. Can anyone clarify what "storage" this error is referring to? Matthew McDermott, MVP SPS Event Type: Error Event Source: Office SharePoint Server Event Category: Office Server Shared Services Event ID: 6482 Date: 1/26/2007 Time: 8:50:


RE: Using LDAP authentication in MOSS 2007
I've found a few articles to get this working but am having no success authenticating to ldap. There is a blog here http://www.sharepointblogs.com/helloisliam/archive/2006/08/15/10027.aspx that runs through the process when authenticating against a non AD ldap (domino). I've used the following


Event ID: 6482 after installation
After an install of MOSS 2007 on Win server 2003 R2 we receive the same error each 1 min when the App Server Admin job fails. Does any one know why the job is failing? We used a standard installation configuration. No known RSA/Crypto settings are set on the SharePoint config. Tried reinstalling S


how to:MossMenu sourcecode
Hi, I've just downloaded the new mossmenu sourcode which i'm supposed to use to replace the current moss topNav menu. Is there anyone who has successfully done this? Please i need help on how exactly to go about doing this. Thanks, Stark

SharePoint Data View Web Part Extension Functions in the ddwrt Namespace

http://msdn2.microsoft.com/en-us/library/aa505323.aspx