views:

352

answers:

2

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?

A: 

I believe the simplest workaround is to find out the InternalNames of the built-in fields, put them in an array, and then to check if the fieldname is in that array or not. For instance, you will most likely have "Title", "Created", "Author" et cetera. This page will give you some hints, which of the fields are built-in: http://www.johnholliday.net/downloads/fieldswss.htm

naivists
A: 

You can use SPField.Group to find out if a field is a 'Base' column such as ID/Author etc or a custom column which will be a question or page separator.

The page separator is a particular field type so you should be able to get those by

if (SPField.Type == SPFieldTypes.PageSeperator)
Ryan
Can I get at that information via a web service?
paul
Opps - me bad. Didn't read the Q properly! You should be able to use the GetList web service to get the schema of the list and the types of its fields.http://msdn.microsoft.com/en-us/library/lists.lists.getlist.aspx
Ryan