How to get persons who have responsed to a survey in MOSS?
laputa.sky - Posted on 2008年8月7日 20:54:46
You know ,i create a survey and hope people to response to it.
However ,how can i get the list of people who have already responsed to the survey?
--------------------------------------------------------------------------------
Michael Washam - MSFTMSFT, Moderator - Posted on 2008年8月8日 0:21:23
The responses are just list items in the survey list.
SPList spl = spw.Lists["testsurvey"];
foreach (SPListItem spli in spl.Items)
{
Console.WriteLine(spli["Completed"].ToString());
Console.WriteLine(spli["Created By"].ToString());
}
--------------------------------------------------------------------------------
From:http://darrenjohnstone.net/2008/06/07/sharepoint-quick-surveys-102/?
For those who are interested, the correct code to determine if the current user has submitted a response to a survey is as follows:
-
/// <summary>
-
/// Determines if the user has already responsed to this survey.
-
/// </summary>
-
/// <returns>True if the user has already responsed.</returns>
-
bool AlreadyResponded()
-
{
-
SPQuery query = new SPQuery();
-
query.Query = String.Format("<Where><Eq><FieldRef Name='Author'/><Value Type='User'>{0}</Value></Eq></Where>",
SPContext.Current.Web.CurrentUser.LoginName);
-
return (theList.GetItems(query).Count > 0);
-
}
I had previosuly made the mistake of forgetting to put Type='User'
in the FieldRef
element. This results in the query failing.
Hopefully this will be of use to you all. Please keep giving feedback either by posting a comment or sending me an email.