I have developed a web part which relies on a list to work so I've created a feature which creates the list with all the necessary columns etc.
When i delpoy to local everything works as it should, list is created etc etc. When I then upload that feature to SP2010 online the lists are not created. Do i need to use different code when a webpart is NOT being deployed but installed? Little confused.
Public Overrides Sub FeatureActivated(ByVal properties As SPFeatureReceiverProperties)
Try
'get the current web object.
' choose your site
'Dim currentSite As SPWeb = SPContext.Current.Web
'local site
'Dim site As SPSite = New SPSite("http:xxxxxxxxxxxxxxxxxxxxx")
'live se
Dim site As SPSite = New SPSite(" https:xxxxxxxxxxxxxxxxxxxx")
Dim web As SPWeb = site.OpenWeb()
Dim lists As SPListCollection = Web.Lists
' create new Generic list called "My List"
' first lets check if it exisits.
Dim ProjectList As SPList = web.Lists.TryGetList("ProfilesTest")
If ProjectList Is Nothing Then
lists.Add("Profiles", "List to populate the Profiles Web part", SPListTemplateType.GenericList)
End If
Dim newList As SPList = web.Lists("Profiles")
' create Text type new column called "My Column"
newList.Fields.Add("Name", SPFieldType.Text, True)
newList.Fields.Add("Company", SPFieldType.Text, True)
newList.Fields.Add("Postion", SPFieldType.Text, True)
newList.Fields.Add("Home", SPFieldType.Text, True)
newList.Fields.Add("Profile", SPFieldType.Note, True)
newList.Fields.Add("Personal", SPFieldType.Note, False)
newList.Fields.Add("Twitter", SPFieldType.Text, False)
newList.Fields.Add("Email", SPFieldType.Text, False)
newList.Fields.Add("Linkedin", SPFieldType.Text, False)
newList.Fields.Add("Order", SPFieldType.Number, False)
newList.Fields.Add("ProfileImage", SPFieldType.URL, False)
newList.Update()
'we can add content in here if we want
Dim currentList As SPList = web.Lists("Profiles")
Dim newlistItem As SPListItem = currentList.Items.Add
newlistItem("Name") = "xxx xxx"
newlistItem("Position") = "xxx xxx"
newlistItem.Update()
' make new column visible in default view
Dim view As SPView = newList.DefaultView
view.ViewFields.Add("Name")
view.ViewFields.Add("Company")
view.Update()
Catch
End Try
End Sub