4

I am wanting to access survey information via the Lists web service and display the questions contained in the survey.

The result contains a large number of Field nodes some of which are the questions in the survey. The other fields contain other information such as author, last changed etc.

How can I pick out the questions? I had thought that all non-questions would be hidden but this is not the case.

Here is my code as it is at the moment. It returns about 16 items. The survey has 6 questions...

// read question definitions
string[] HandleTypes = new string[] { "Number", "DateTime", "Text", "Choice", "GridChoice", "Boolean" };
var query = from n in node.Descendants(ns+"Field")
            where (n.Attribute("Hidden") == null || n.Attribute("Hidden").Value.ToLower() == "true")
            && (n.Attribute("Type") != null && HandleTypes.Contains(n.Attribute("Type").Value))
            select new Question(n.Attribute("ID").Value)
            {
                Text = n.Attribute("DisplayName").Value,
                QuestionType = n.Attribute("Type").Value,
                Element = n
            };

Ideas anyone?

0

Not sure if this is a global solution but it seems to work for me.

If I only take Fields which have a Version attribute then I just get my questions.

So my query looks like this:

var query = from n in node.Descendants(ns+"Field")
            where (n.Attribute("Hidden") == null || n.Attribute("Hidden").Value.ToLower() == "true")
            && (n.Attribute("Version") != null)
            select new Question(n.Attribute("ID").Value)
            {
                Text = n.Attribute("DisplayName").Value,
                QuestionType = n.Attribute("Type").Value,
                Element = n
            };

I'm going to try this to see how far it goes...

  • UPDATE - unfortunately, it is not good enough. There are some questions which do not have the version attribute :-( Back to the drawing board.... – paul Mar 16 '10 at 9:07
0

I do like this :

I noticed that for the fields which are not questions the attribute SourceId = "http://schemas.microsoft.com/sharepoint/v3". So I take the fields where SourceId doesn't contains sharepoint.

You also might want to take the fields Author, Created, Modified

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.