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:

  1. /// <summary>  
  2. /// Determines if the user has already responsed to this survey.  
  3. /// </summary>  
  4. /// <returns>True if the user has already responsed.</returns>  
  5. bool AlreadyResponded()  
  6. {  
  7.     SPQuery query = new SPQuery();  
  8.     query.Query = String.Format("<Where><Eq><FieldRef Name='Author'/><Value Type='User'>{0}</Value></Eq></Where>"

    SPContext.Current.Web.CurrentUser.LoginName);  

  9.     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.


 

 

posted @ 2008-09-25 22:32  laputa'sky  阅读(259)  评论(0编辑  收藏  举报