PreValues and Category Lists - is there an easier way?
Hi everyone,
I'm importing a website into v7.5.2 and want to populate some prevalues in a category list.
I've added a subsection of my code below (in VB) which does work.
My question is, is there an easier way to look for the prevalue?
'using umbraco's services ...
Dim cs As IContentService = ApplicationContext.Current.Services.ContentService
Dim dts As IDataTypeService = ApplicationContext.Current.Services.DataTypeService
'...get the data (not shown here)
'process a datatable returned from a database query
For Each dr In dt.Rows
''Create a new document with the document type alias (under Settings in the Umbraco backoffice)
Dim doc As Content = cs.CreateContent(dr("title").ToString, -1, "orgDocType")
doc.SetValue("page_id", CInt(dr("page_id").ToString))
' ... set other values in the document (not shown here)
'*** Start: The code below gets the prevalue id of the Category List so I can programmatically add it to the database
'***
Dim dataType = dts.GetDataTypeDefinitionByName("Category List")
Dim preValues As XPathNodeIterator = GetPreValues(dataType.Id)
preValues.MoveNext()
Dim myIterator As XPathNodeIterator = preValues.Current.SelectChildren("preValue", "")
Dim myCategory As Integer = 0
While (myIterator.MoveNext())
'note - compare the value to the value in the database dr("p_categorylist")
If myIterator.Current.Value = dr("p_categorylist").ToString Then
myCategory = CInt(myIterator.Current.GetAttribute("id", ""))
End If
'lblMessage.Text = lblMessage.Text + myIterator.Current.Value & " " & myIterator.Current.GetAttribute("id", "") & "<br>"
End While
'***
'*** End: Category List
'if myCategory is not 0 then set the prevalue
doc.SetValue("categorylist", myCategory)
'Save and publish
cs.SaveAndPublishWithStatus(doc)
Next
PreValues and Category Lists - is there an easier way?
Hi everyone, I'm importing a website into v7.5.2 and want to populate some prevalues in a category list.
I've added a subsection of my code below (in VB) which does work.
My question is, is there an easier way to look for the prevalue?
is working on a reply...