By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,079 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

Need help changing field properties of a sharepoint list

kaptaineaux
P: 2
Hi,

What I am trying to do is update a field in list programmatically using a webpart. What I do is I get the context of the site, then all lists of type Events. For each End field that is apart of those lists, I want to make that field required. The problem I'm running into, on Update(), the change does not take. I have no idea what's going on. Here is my code:

protected override void OnLoad(EventArgs e)
{

SPSite mysite = SPControl.GetContextSite(Context);
SPWeb currentweb = SPControl.GetContextWeb(Context);
SPWebCollection subsites = mysite.AllWebs;
SPWebPartCollection webparts_ = currentweb.GetWebPartCollection("default.aspx",Sto rage.Shared);
try
{
foreach(SPWeb website in subsites)
{
SPListCollection lists = website.Lists;

for (int i=(lists.Count-1); i>=0; i--)
{
if(lists[i].BaseTemplate == SPListTemplateType.Events)
{
lists[i].Fields["End"].Required = true;

lists[i].Fields["End"].Update();

}
}
catch (Exception err)
{
//statements
}
}
}

Any assistance would be greatly appreciated.

Thanks
Apr 19 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.