Usually we use the follow spquery to make sure whether a user has given a answer to our surveys:
Here we suppose you run these code in the Administrator's role:
Code
String siteurl = "http ://****";
String userforcheck = "domain \ useraccount ";
// Check whether the user has responded to the survey
Bool result = false;
// Check whether the user has completed the answer
Bool isrespondcomplete = false;
Spsecurity. runwithelevatedprivileges (delegate ()
{
Using (spsite site = new spsite (siteurl ))
{
Using (spweb = site. rootweb)
{
Spuser imitationuser = web. ensureuser (userforcheck );
Using (spsite sitewithuser = new spsite (siteurl, user. usertoken ))
{
Using (spweb webwithuser = sitewithuser. rootweb)
{
Spquery q = new spquery ();
Q. query = @ "<where>
<EQ>
<Fieldref name = \ "author \"/>
<Value type = \ "user \"> "+ spuser. Name + @" </value>"
</EQ>
</Where>"
Splist list = webwithuser. Lists ["your survey's name"];
Splistitemcollection items = List. getitems (query );
If (items. Count> 0)
{
Result = true;
Isrespondcomplete = items [0] ["completed"]. tostring () = "1 ";
}
}
}
}
}
});