Re: Return only spfields that are filterable
Hi Paul, Here is a sample you can start with. using(SPSite site = new SPSite(http://localhost;)) using (SPWeb web = site.OpenWeb()) { ListSPField fieldsList = new ListSPField(); SPFieldCollection fieldsCollection = web.Fields; foreach (SPField field in fieldsCollection) { Console.WriteLine(field.Title); fieldsList.Add(field); } } Use fieldsList to populate your DropDownList. You can also get Fields Collection for your lists in the same way, Cheers, Salman From: Paul Noone Sent: Thursday, November 03, 2011 8:52 AM To: mailto:ozmoss@ozmoss.com Subject: Return only spfields that are filterable Can anyone provide an example of how I can use the SPField.Filterable property to return all fields where this is true? I want to use this to dynamically populate a DropDownList control. ___ ozmoss mailing list ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss ___ ozmoss mailing list ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss
Re: Return only spfields that are filterable
my bad, I missed actual condition, foreach (SPField field in fieldsCollection) { if (field.Filterable) { Console.WriteLine(field.Title); fieldsList.Add(field); } } Cheers, From: Salman Ahmad Sent: Thursday, November 03, 2011 11:24 AM To: ozMOSS Subject: Re: Return only spfields that are filterable Hi Paul, Here is a sample you can start with. using(SPSite site = new SPSite(http://localhost;)) using (SPWeb web = site.OpenWeb()) { ListSPField fieldsList = new ListSPField(); SPFieldCollection fieldsCollection = web.Fields; foreach (SPField field in fieldsCollection) { Console.WriteLine(field.Title); fieldsList.Add(field); } } Use fieldsList to populate your DropDownList. You can also get Fields Collection for your lists in the same way, Cheers, Salman From: Paul Noone Sent: Thursday, November 03, 2011 8:52 AM To: mailto:ozmoss@ozmoss.com Subject: Return only spfields that are filterable Can anyone provide an example of how I can use the SPField.Filterable property to return all fields where this is true? I want to use this to dynamically populate a DropDownList control. ___ ozmoss mailing list ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss ___ ozmoss mailing list ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss ___ ozmoss mailing list ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss
RE: Return only spfields that are filterable
:) Great. That's exactly what I was after. Thank you! One more question surrounding using. Whenever I use using I get web part errors saying that the data has already been disposed. This usually occurs when trying to edit the web part properties. As a result, I now just do the folowing but am unsure as to whether this needs to be disposed at some point? try { oList = SPContext.Current.Web.Lists[oListName]; From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Salman Ahmad Sent: Thursday, 3 November 2011 6:29 PM To: ozMOSS Subject: Re: Return only spfields that are filterable my bad, I missed actual condition, foreach (SPField field in fieldsCollection) { if (field.Filterable) { Console.WriteLine(field.Title); fieldsList.Add(field); } } Cheers, From: Salman Ahmadmailto:salman.ah...@msn.com Sent: Thursday, November 03, 2011 11:24 AM To: ozMOSSmailto:ozmoss@ozmoss.com Subject: Re: Return only spfields that are filterable Hi Paul, Here is a sample you can start with. using(SPSite site = new SPSite(http://localhost;)) using (SPWeb web = site.OpenWeb()) { ListSPField fieldsList = new ListSPField(); SPFieldCollection fieldsCollection = web.Fields; foreach (SPField field in fieldsCollection) { Console.WriteLine(field.Title); fieldsList.Add(field); } } Use fieldsList to populate your DropDownList. You can also get Fields Collection for your lists in the same way, Cheers, Salman From: Paul Noonemailto:paul.no...@ceosyd.catholic.edu.au Sent: Thursday, November 03, 2011 8:52 AM To: mailto:ozmoss@ozmoss.com Subject: Return only spfields that are filterable Can anyone provide an example of how I can use the SPField.Filterable property to return all fields where this is true? I want to use this to dynamically populate a DropDownList control. ___ ozmoss mailing list ozmoss@ozmoss.commailto:ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss ___ ozmoss mailing list ozmoss@ozmoss.commailto:ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss ___ ozmoss mailing list ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss
Re: Return only spfields that are filterable
You will not need to dispose SPContext, As a general rule if we create an object only then we dispose it.. On Fri, Nov 4, 2011 at 11:35 AM, Paul Noone paul.no...@ceosyd.catholic.edu.au wrote: Damn. I may need to trim that even further. J Suggestions? Incidentally, I am using a DropDownList control and the following worked a treat. Never ceases to amaze me just how simple these things are when you know how. Huge thanks to Techardinal’s series on Editor Partshttp://blog.techardinal.com/categories/263/web-part-development.aspx. Making sense out of the dark arts. J public class ListSettingsPart: EditorPart { // Declare custom editor parts here DropDownList SortByCol = new DropDownList(); ** ** // Get filterable columns for the DropDownList private void popSortByCol_dd() { // Get reference to the web part LightBox lbWebPart = (LightBox)WebPartToEdit; // Get list and field collection SPList imageLib = SPContext .Current.Web.Lists[lbWebPart.oListName]; SPFieldCollection fieldsCollection = imageLib.Fields; ** ** foreach (SPField field in fieldsCollection) { // Get only filterable fields if (field.Filterable) { SortByCol.Items.Add(new ListItem {Text = field.Title, Value = field.InternalName }); } } ** ** } ** ** // Create our controls protected override void CreateChildControls() { // Clear any existing controls this.Controls.Clear(); ** ** // Create the custom control panel Panel panListSettings = new Panel(); ** ** // Create SortByCol label Label labSortByCol = new Label(); labSortByCol.Text = SortBy column:; panListSettings.Controls.Add(labSortByCol); // Populate the dropdownlist popSortByCol_dd(); SortByCol.ToolTip = Select a column to sort by.; SortByCol.AutoPostBack = true; panListSettings.Controls.Add(SortByCol); // Add the custom control panel this.Controls.Add(panListSettings); } ** ** *From:* ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] *On Behalf Of *Paul Noone *Sent:* Friday, 4 November 2011 8:31 AM *To:* ozMOSS *Subject:* RE: Return only spfields that are filterable ** ** J Great. That’s exactly what I was after. Thank you! One more question surrounding “using”. Whenever I use using I get web part errors saying that the data has already been disposed. This usually occurs when trying to edit the web part properties. As a result, I now just do the folowing but am unsure as to whether this needs to be disposed at some point? try { oList = SPContext.Current.Web.Lists[oListName]; ** ** *From:* ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] *On Behalf Of *Salman Ahmad *Sent:* Thursday, 3 November 2011 6:29 PM *To:* ozMOSS *Subject:* Re: Return only spfields that are filterable ** ** my bad, I missed actual condition, foreach (SPField field in fieldsCollection) { if (field.Filterable) { Console.WriteLine(field.Title); fieldsList.Add(field); } } Cheers, *From:* Salman Ahmad salman.ah...@msn.com *Sent:* Thursday, November 03, 2011 11:24 AM *To:* ozMOSS ozmoss@ozmoss.com *Subject:* Re: Return only spfields that are filterable Hi Paul, Here is a sample you can start with. using(SPSite site = new SPSite(http://localhost;)) using (SPWeb web = site.OpenWeb()) { ListSPField fieldsList = new ListSPField(); SPFieldCollection fieldsCollection = web.Fields; foreach (SPField field in fieldsCollection) { Console.WriteLine(field.Title); fieldsList.Add(field); } } Use fieldsList to populate your DropDownList. You can also get Fields Collection for your lists in the same way, Cheers, Salman *From:* Paul Noone paul.no...@ceosyd.catholic.edu.au *Sent:* Thursday, November 03, 2011 8:52 AM *To:* mailto:ozmoss@ozmoss.com ozmoss@ozmoss.com *Subject:* Return only spfields