Solved

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

Posted on 2010-09-07
3
630 Views
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
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
Comment
Question by:AaronHPackard
3 Comments
 
LVL 29

Accepted Solution

by:
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.
0
 
LVL 17

Expert Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SharePoint Designer 2013 4 62
Citrix sharefile 1 70
Date Differences SSRS 3 66
Please explain "Promise Pattern" and how it's used 2 56
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
I used to be SharePoint evangelist in our company, so my Outlook always full of questions about how to do this, or where I can find that. One day I found such an email with the following question: "how to attach 3-State workflow (one of the workflow…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

770 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