I have a web part I'm creating that displays links in a metro style fed from a compatible list. I'm pretty new to share point development and was wondering how can I make sure a compatible list is available in the site (im guesssing i need to create a content type) or how can I trigger the creation of a compatible list to feed the webpart and then link the webpart to that list. I was thinking that perhaps i could add a button to the webpart properties panel that will create the list when clicked. Im not sure to be honest. Any ideas are welcome.
is this what your looking for?
Creates a new list:
SPWeb mySite = SPContext.Current.Web; SPListTemplate template = mySite.ListTemplates["Decisions"]; mySite.Lists.Add("My Decisions", "This is a list of decisions", template);
Update list item(s):
SPSite site = SPContext.Current.Site; SPWeb web = site.OpenWeb(); web.AllowUnsafeUpdates = true; SPList list = web.Lists["Decisions"]; SPListItem item = list.GetItemById(Convert.ToInt32(TextBox4.Text)); item["First Name"] = TextBox1.Text;
You can add a button to the webpart properties that triggers the code above ;)
hope it helps :)
Best way to ensure is to create the list with object model at webpart feature activation
See, after deploying webpart you have to activate the web part feature, in that feature activation event (FeatureActivated event receiver) write your code that will create the list for you, you can also write code for list deletion at feature deactivation depending upon your choice
The way I would do it:
- Provide a list definition of the list which will hold the links
- Provide a webpart with customized panel where you can choose which list (of the type above) should be used as source.
The user who adds the webpart should also create a new list for it. Creating lists and adding webparts to the page is probably not a daily activity. So I am not sure if it's worth investing any more time in a more sophisticated approach.
I hope it helped.