How do I set up my silverlight app to pull data from a sharepoint list based on user inputs?

Posted on 2010-09-07
Last Modified: 2013-11-12
I have a silverlight app that I have hosted on a SharePoint 2010 site. The application pulls data from various lists on the site according to user inputs. At first, everything works fine. However, once the user tries to pull the data again based on a new criteria (but using the same listcollection) I get the error below...

Webpage error details

Message: Unhandled Error in Silverlight Application The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.   at Microsoft.SharePoint.Client.ClientObjectCollection`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>d__0.MoveNext()
   at POSS.MainPage.BindGetProjectData()
Line: 1
Char: 1
Code: 0

I think it has to do with the fact that I'm using the same list collection over and over again depending on the subject area, but I don't know of another way to do it. Any ideas? I've attached some of my code. "GetThisProject()" method is called when the user choses a new project.
Partial Public Class MainPage
Inherits UserControl
Private _TheseIssues As ListItemCollection
Private context As ClientContext = New ClientContext(ApplicationContext.Current.Url)
Private oWebsite As Web = context.Web
Private spl_Portfolio As List = context.Web.Lists.GetByTitle("Portfolio")

Public Sub New()
End Sub

Private Sub GetThisProject()

        Me.myProgressBar.Visibility = Windows.Visibility.Visible
        Me.myProgressText.Visibility = Windows.Visibility.Visible

        'Get List of User's Projects -------------------------------------------------------------------------------------------
        Dim query As CamlQuery = New CamlQuery()
        Dim camlQueryXml As String = "<View><Query><Where><Eq><FieldRef Name=""Title"" /><Value Type='Text'>" + ChosenProject + "</Value></Eq></Where></Query><ViewFields>" + _
            "<FieldRef Name=""Title"" /><FieldRef Name=""Project_x0020_No"" /><FieldRef Name=""L3_x0020_Organization"" /><FieldRef Name=""L3_x0020_Manager"" /><FieldRef Name=""L4_x0020_Manager"" /><FieldRef Name=""Project_x0020_Status"" /><FieldRef Name=""Project_x0020_Condition"" /><FieldRef Name=""Project_x0020_Phase"" /><FieldRef Name=""Project_x0020_Manager"" /><FieldRef Name=""Top_x0020_200"" /><FieldRef Name=""CBA_x0020_Status"" />" + _
            "<FieldRef Name=""Forecasted_x0020_Finish_x0020_Qu"" /><FieldRef Name=""Solution_x0020_Short_x0020_Descr"" /><FieldRef Name=""Issues"" /><FieldRef Name=""Planning_x0020_State"" /><FieldRef Name=""Last_x0020_Updated"" /><FieldRef Name=""Planned_x0020_Completion_x0020_Q"" /><FieldRef Name=""Portfolio_x0020_Project_x0020_Ty"" /><FieldRef Name=""Innovation_x0020_Priority_x0020_"" /><FieldRef Name=""Reason_x0020_Late"" /><FieldRef Name=""Business_x0020_or_x0020_IT"" /><FieldRef Name=""IT_x0020_Innovation_x0020_Priori"" /><FieldRef Name=""Ec_x0020_Manager_x0020_Priority_"" /><FieldRef Name=""Domain_x0020_Council_x0020_Ranki"" /><FieldRef Name=""Sizing_x0020_Tier"" /><FieldRef Name=""Expected_x0020_Start_x0020_Perio"" /><FieldRef Name=""Expected_x0020_Finish_x0020_Peri"" /><FieldRef Name=""Planning_x0020_Phase_x0020_Basel"" />" + _
            "<FieldRef Name=""Planning_x0020_Phase_x0020_Basel0"" /><FieldRef Name=""Development_x0020_Phase_x0020_Ba"" /><FieldRef Name=""Development_x0020_Phase_x0020_Ba0"" /><FieldRef Name=""Warranty_x0020_Phase_x0020_Basel"" /><FieldRef Name=""Warranty_x0020_Phase_x0020_Basel0"" /><FieldRef Name=""Planning_x0020_Phase_x0020_Actua"" /><FieldRef Name=""Planning_x0020_Phase_x0020_Actua0"" /><FieldRef Name=""Development_x0020_Phase_x0020_Ac"" /><FieldRef Name=""Development_x0020_Phase_x0020_Ac0"" /><FieldRef Name=""Warranty_x0020_Phase_x0020_Actua"" /><FieldRef Name=""Warranty_x0020_Phase_x0020_Actua0"" /><FieldRef Name=""Current_x0020_Forecast_x0020_Fin"" /><FieldRef Name=""Planned_x0020_IT_x0020_Costs"" /><FieldRef Name=""Development_x0020_Forecast_x0020"" /><FieldRef Name=""Project_x0020_Structure_x0020_Ty"" /><FieldRef Name=""Summary_x0020_Phase"" /><FieldRef Name=""Current_x0020_FY_x0020_Above_x00"" /><FieldRef Name=""Data_x0020_Date"" />" + _
            "<FieldRef Name=""Accomplishments"" /><FieldRef Name=""Next_x0020_Steps"" /><FieldRef Name=""Color_PBFD"" /><FieldRef Name=""Color_PAFD"" /><FieldRef Name=""Color_DBFD"" /><FieldRef Name=""Color_DFFD"" /><FieldRef Name=""Color_DAFD"" /><FieldRef Name=""Color_WBFD"" /><FieldRef Name=""Color_CFFD"" /><FieldRef Name=""Color_WAFD"" /><FieldRef Name=""Color_CBAStatus"" /><FieldRef Name=""Color_OTD"" /><FieldRef Name=""Business_x0020_PM"" /><FieldRef Name=""IT_x0020_Manager"" /><FieldRef Name=""Status_x0020_Summary"" /></ViewFields></View>"
        query.ViewXml = camlQueryXml
        _ThisProject = spl_Portfolio.GetItems(query)
        context.ExecuteQueryAsync(New ClientRequestSucceededEventHandler(AddressOf OnGetProjectRequestSucceeded), Nothing)

    End Sub

Private Sub OnGetProjectRequestSucceeded(ByVal sender As Object, ByVal args As ClientRequestSucceededEventArgs)
        Dispatcher.BeginInvoke(New Action(AddressOf BindGetProjectData))
    End Sub

Private Sub BindGetProjectData()
        Dim projects As List(Of Project) = New List(Of Project)()
        Dim pdates As List(Of ProjectDates) = New List(Of ProjectDates)()
        Dim nextTrigger As Integer = 0
        Dim nextproject As String = Nothing
        For Each li As ListItem In _ThisProject ' The error occurs around here
            ps_ProjectNo.Text = li("Project_x0020_No")
            ps_ProjectName.Text = li("Title")
            ps_ProjectCondition.Text = li("Project_x0020_Condition")
            ps_ProjectPhase.Text = li("Project_x0020_Phase")
            ps_Status.Text = li("Project_x0020_Status")
            ps_ITManager.Text = li("IT_x0020_Manager")
            ps_ITPM.Text = li("Project_x0020_Manager")
            ps_BusinessPM.Text = li("Business_x0020_PM")
            ps_SSD.Text = li("Solution_x0020_Short_x0020_Descr")
            ps_Accomplishments.Text = li("Accomplishments")
            ps_NextSteps.Text = li("Next_x0020_Steps")
            If li("Planning_x0020_Phase_x0020_Basel0") IsNot Nothing Then ps_PBFD.Text = li("Planning_x0020_Phase_x0020_Basel0").ToShortDateString()
            If li("Development_x0020_Phase_x0020_Ba0") IsNot Nothing Then ps_DBFD.Text = li("Development_x0020_Phase_x0020_Ba0").ToShortDateString()
            If li("Development_x0020_Forecast_x0020") IsNot Nothing Then ps_DFFD.Text = li("Development_x0020_Forecast_x0020").ToShortDateString()
            If li("Warranty_x0020_Phase_x0020_Basel0") IsNot Nothing Then ps_WBFD.Text = li("Warranty_x0020_Phase_x0020_Basel0").ToShortDateString()
            If li("Planning_x0020_Phase_x0020_Actua0") IsNot Nothing Then ps_PAFD.Text = li("Planning_x0020_Phase_x0020_Actua0").ToShortDateString()
            If li("Development_x0020_Phase_x0020_Ac0") IsNot Nothing Then ps_DAFD.Text = li("Development_x0020_Phase_x0020_Ac0").ToShortDateString()
            If li("Warranty_x0020_Phase_x0020_Actua0") IsNot Nothing Then ps_WAFD.Text = li("Warranty_x0020_Phase_x0020_Actua0").ToShortDateString()
            If li("Current_x0020_Forecast_x0020_Fin") IsNot Nothing Then ps_CFFD.Text = li("Current_x0020_Forecast_x0020_Fin").ToShortDateString()
            For Each mi As AgMenuItem In agm_Projects.Items
                nextTrigger = 0
                For Each miproj As AgMenuItem In mi.Items
                    If nextTrigger = 1 Then
                        nextproject = miproj.Header
                        Exit For
                    End If
                    If miproj.Header <> li("Title") Then
                        prvprj.Text = miproj.Header
                        miproj.Header = li("Title")
                        nextTrigger = 1
                    End If
                Next miproj
                If nextTrigger = 1 Then
                    nxtprj.Text = nextproject
                    Exit For
                End If
            Next mi
            ps_ColorProjectCondition.Background = PConditionSwatch(li("Project_x0020_Condition"))
            ps_ColorPBFD.Fill = PConditionSwatch(li("Color_PBFD"))
            ps_ColorPAFD.Fill = PConditionSwatch(li("Color_PAFD"))
            ps_ColorDBFD.Fill = PConditionSwatch(li("Color_DBFD"))
            ps_ColorDFFD.Fill = PConditionSwatch(li("Color_DFFD"))
            ps_ColorDAFD.Fill = PConditionSwatch(li("Color_DAFD"))
            ps_ColorWBFD.Fill = PConditionSwatch(li("Color_WBFD"))
            ps_ColorCFFD.Fill = PConditionSwatch(li("Color_CFFD"))
            ps_ColorWAFD.Fill = PConditionSwatch(li("Color_WAFD"))
            ps_ColorCBA.Fill = PConditionSwatch(li("Color_CBAStatus"))
            ps_ColorOTD.Fill = PConditionSwatch(li("Color_OTD"))

            If li("Project_x0020_Condition") = "Yellow" Or li("Project_x0020_Condition") = "Red" Then
                ps_opt_StatusSum.Visibility = Windows.Visibility.Visible
                ps_StatusSummary.Visibility = Windows.Visibility.Visible
                ps_grd_Accomplishments.Margin = New Thickness(0, 8, 0, 0)
                ps_StatusSummary.Text = li("Status_x0020_Summary")
                ps_opt_StatusSum.Visibility = Windows.Visibility.Collapsed
                ps_StatusSummary.Visibility = Windows.Visibility.Collapsed
                ps_grd_Accomplishments.Margin = New Thickness(0, 0, 0, 0)
            End If

        For Each pj As Project In projects
            nxtprj.text = projects(pj.ProjectListID + 1).PName
        Me.myProgressText.Text = "Done!"
        Me.myProgressText.Visibility = Windows.Visibility.Collapsed
        Me.myProgressBar.Visibility = Windows.Visibility.Collapsed
        Me.myProgressText.Text = "Loading..."
    End Sub

Open in new window

Question by:AaronHPackard
LVL 29

Accepted Solution

Gautham Janardhan earned 500 total points
ID: 33668443
you need to make a call to context.Web.Retrieve(WebPropertyNames.Id,WebPropertyNames.Title) before calling the ExecuteQueryAsync.
LVL 17

Expert Comment

ID: 36123445
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question