0

I created a custom webpart with inside it the pageviewer webpart. How can I check programmatically if the current user has finished the survey questions?

Note It is also possible to save the survey questions without finished it.

  • Have you tried with clientside javascript? – Aleksandar Jun 1 '15 at 12:11
  • no, but I don't know how. – Ola Jun 1 '15 at 12:14
0

I found the solution by my self:

private bool IsSurveyCompleted()
        {
            bool result = false;

            // check if the url is not null or empty
            if (!string.IsNullOrEmpty(_SurveyListUrl))
            {
                    using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                    {
                        using (SPWeb web = site.RootWeb)
                        {
                            // get completed survey list item for current user
                            SPQuery q = new SPQuery();
                            var userId = SPContext.Current.Web.CurrentUser.ID;
                            q.Query = string.Format("<Where><And><Eq><FieldRef Name=\"Completed\" /><Value Type=\"Boolean\">1</Value></Eq><Eq><FieldRef Name=\"Author\" LookupId=\"True\"/><Value Type=\"User\">{0}</Value></Eq></And></Where>", userId);

                            SPList list = web.GetList(_SurveyListUrl); 

                            if (list != null)
                            {
                                SPListItemCollection items = list.GetItems(q);

                                if (items.Count > 0)
                                {
                                 result = true;
                                }
                            }
                        }
                    }
            }

            return result;

        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.