Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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