프로그래밍 방식으로 설문 조사에서 질문을하는 방법
-
29-09-2020 - |
문제
질문은 매우 간단합니다 :
조사에서 질문 목록을 어떻게 얻을 수 있습니까?
해결책
Survey
List의 질문은 필드입니다.필드가 질문이나 일반 필드인지 여부를 확인하려면 SourceID
속성을 활용할 수 있습니다. 그 값이 http://schemas.microsoft.com/sharepoint/v3
가 아닌 경우 :
/// <summary>
/// Get questions in Survey List
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public static IEnumerable<SPField> GetSurveyQuestions(SPList list)
{
return (from SPField field in list.Fields
let fieldSchema = XElement.Parse(field.SchemaXml)
let sourceId = fieldSchema.Attribute("SourceID").Value
where sourceId != "http://schemas.microsoft.com/sharepoint/v3"
select field).ToList();
}
.
사용법
using (var site = new SPSite(siteUrl))
{
using (var web = site.OpenWeb())
{
var list = web.Lists[surveyName];
var questions = GetSurveyQuestions(list);
//print questions
foreach (var question in questions)
{
Console.WriteLine(question.Title);
}
}
}
. 다른 팁
지금 당장 발견 한 유일한 대답은 다음과 같습니다. 각 필드의 ShowInVersionHistory 속성 확인!
using (SPSite sito = new SPSite("URL"))
{
using (SPWeb web = sito.OpenWeb())
{
var list = web.Lists["SURVEY LIST NAME"];
foreach(var Field in list.Fields.Cast<SPField>().Where(x => x.ShowInVersionHistory))
{
Console.WriteLine(Field.ToString());
}
}
}
.
내 경우에는 모든 질문이 인쇄됩니다
그 일을하는 더 좋은 방법이 있습니까?
제휴하지 않습니다 sharepoint.stackexchange