Sitefinity 4.1 List in VB

Posted by Community Admin on 04-Aug-2018 12:09

Sitefinity 4.1 List in VB

All Replies

Posted by Community Admin on 01-Jul-2011 00:00

Hi

I have  a list in sitefinity which I am trying to access with a code behind  in a master template

My list is called 'FAQ'

My VB is

Imports Telerik.Sitefinity.Modules.Lists
Imports Telerik.Sitefinity.Lists.Model
 
Public Class InsiderControl
    Inherits System.Web.UI.UserControl
 
    Public Function FindList(ByVal listTitle As String) As List
        Dim manager As ListsManager = ListsManager.GetManager()
        Dim listToLocate As List = manager.GetLists().Where(Function(l) l.Title = listTitle).[Single]()
        Return listToLocate
    End Function
 
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
 
        'Register styles
        ScriptManager.RegisterStartupScript(Me.Page, GetType(Page), "insiderControlStyles", String.Format("<link rel='stylesheet' media='screen' type='text/css' href='0' />", ResolveUrl("InsiderArea.css")), False)
 
        'Registers javascript/jQuery
        ScriptManager.RegisterStartupScript(Me.Page, GetType(Page), "insiderControl", String.Format("<script src='0' type='text/javascript'></script>", ResolveUrl("InsiderControl.js")), False)
 
        FindList("FAQ")
 
 
    End Sub
 
End Class

The text in bold'Manager.GetLists().Where(Function(l) l.Title = listTitle).[Single]()'
is returning an error, when I build Im getting
'Error    1    Overload resolution failed because no accessible 'Where' can be called with these arguments:'

Any one any ideas where Im going wrong?

Cheers

Andrew

Posted by Community Admin on 01-Jul-2011 00:00

Hello Andrew,

The Title property of built in modules is of type LString in order to support localization. While C# allows the comparing of LString with string directly in VB you have to explicitly complare the Value property of the LString type with the parameter:

Manager.GetLists().Where(Function(l) l.Title.Value = listTitle)

Kind regards,
Radoslav Georgiev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 01-Jul-2011 00:00

great, thats sorted it

Thanks

Posted by Community Admin on 13-Jul-2011 00:00

or at least I thought it hade sorted the issue

I am now getting the error

Property 'System.String Value' is not defined for type 'System.String'

Any ideas as to the problem here?

Posted by Community Admin on 18-Jul-2011 00:00

Hello Andrew,

Can you please check the Where statement? Are you using Title again? If you are filtering for some other field it might be declared as a string, so Value is not needed there. Please check the return type of the property. Also try to declare the filtering parameters as local variables:

Public Function FindList(ByVal listTitle As String) As List
    Dim manager As ListsManager = ListsManager.GetManager()
    Dim titleToFind As String = listTitle
    Dim listToLocate As List = manager.GetLists().Where(Function(l) l.Title = titleToFind).[Single]()
    Return listToLocate
End Function


Kind regards,
Radoslav Georgiev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 21-Apr-2012 00:00

Maybe try GetLists().ToList().Where....

This thread is closed