Monday 9 June 2008

Last created Survey which has only one question

[TR]
Bir WebPart için site üzerindeki en son girilen tek soruluk anket bilgisini almam gerekti. Site üzerinde oluşturulan anketler ok ama tek sorulu olanı nasıl almaya çalışacam diye düşünürken anketlerin her bir soruyu bir field olarak tuttuğunu farkettim. Daha sonra moss'taki bir anketin default olarak 42 tane field'ının olduğunu öğrendim ve kodla kontrol ettim. En sonunda ortaya şöyle bir kod parçası çıktı

DateTime created = DateTime.MinValue;
foreach (SPList list in mainWeb.Lists)
{
if (list.BaseType.ToString() == "Survey" && list.Created > created && list.Fields.Count==43)
{
AnketTitle = list.Title.ToString();
}
}

[ENG]
I needed to get the title info of the last created survey which has only one question. It was fine to get last created survey but I was wondering how to get number of questions. Then I realised each question is kept as a field in the survey. I checked that each survey has 42 default fields. Finally I wrote a code like that;

DateTime created = DateTime.MinValue;
foreach (SPList list in mainWeb.Lists)
{
if (list.BaseType.ToString() == "Survey" && list.Created > created && list.Fields.Count==43)
{
AnketTitle = list.Title.ToString();
}
}

No comments: