Adyt
Adyt

Reputation: 1472

survey results in sharepoint

how do i get a list of user that have completed or not completed or not responded to a survey.

so i have a survey, lets say "survey A". in this survey i have a list of people or groups that must fill the survey. sharepoint already gives us a list of respondents, but i want to make a list of people that have not responded or not completed the survey.

i'm using c#, thanks..

Upvotes: 2

Views: 3300

Answers (2)

SaguiItay
SaguiItay

Reputation: 2215

Assuming that your survey is marked as non-anonymous, and that people can't answer the survey more than once, you can do the following:

  1. Take the list of people that MUST fill the survey.
  2. Iterate over the items in the survey (each item is a response from a single person).
  3. Remove the person that created that item from the list of people from section 1. (SharePoint surveys keep the person that answered the survey as the "Creator"/"Author" property of the item)

The result will be the list of people that MUST answer the survey, but haven't done so yet.

Upvotes: 2

vaibhav
vaibhav

Reputation: 21

private DataTable GetUser()
{
    //SPGroup User = null;

    DataTable dt = new DataTable();
    dt.Columns.Add("Survey Remeaning User");

    DataTable dtuser = new DataTable();
    dtuser.Columns.Add("Survey Completed User");


    try
    {
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (SPSite objSubSite = new SPSite(SPContext.Current.Site.Url))
            {
                SPUserCollection userCollection = SPContext.Current.Web.Groups["Survey Members"].Users;
                foreach (SPUser user in userCollection)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<Where>");
                    sb.Append("<Eq>");
                    sb.Append("<FieldRef Name='Author' />");
                    sb.Append("<Value Type='User'>" + user + "</Value>");
                    sb.Append("</Eq>");
                    sb.Append("</Where>");

                    // query.ViewFields = "<FieldRef Name='Author'/>";
                    SPQuery query = new SPQuery();
                    query.Query = sb.ToString();

                    using (SPWeb objWeb = objSubSite.OpenWeb())
                    {
                        int i = objWeb.Lists["SurveyList"].GetItems(query).Count;
                        if (i == 0)
                        {
                            dt.Rows.Add(user);
                            GvUser.DataSource = dt;
                            GvUser.DataBind();
                        }
                        //if (i == 1)
                        else
                        {
                            //DataTable dtuser = new DataTable();
                            //dt.Columns.Add("SurveyCompleted");
                            dtuser.Rows.Add(user);
                            GvComUser.DataSource = dtuser;
                            GvComUser.DataBind();
                        }
                    }
                }
            }
        });
    }
    catch (Exception)
    {


    }
    return dt;
}

you have to create a group in user and group and add user in that. and then u can can user above function and add th function in page load.... i have show the result in grid view by adding coloums in it

Upvotes: 2

Related Questions