Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 639
  • Last Modified:

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

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
URI: http://ea.sharepoint.hp.com/teams/dmits-dashboard/SitePages/DEV%20-%20Full%20DMITS%20Dashboard.aspx

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()
        InitializeComponent()
End Sub

Private Sub GetThisProject()

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

        'Get List of User's Projects -------------------------------------------------------------------------------------------
        context.Load(spl_Portfolio)
        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.Load(_ThisProject)
        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
        ResetProjectStatus()
        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
                    Else
                        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")
            Else
                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

        Next
        For Each pj As Project In projects
            nxtprj.text = projects(pj.ProjectListID + 1).PName
        Next
		
	
        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

0
AaronHPackard
Asked:
AaronHPackard
1 Solution
 
Gautham JanardhanCommented:
you need to make a call to context.Web.Retrieve(WebPropertyNames.Id,WebPropertyNames.Title) before calling the ExecuteQueryAsync.
0
 
GreatGermCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now