Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
lenny76
Regular Visitor

api getreport - sort list

HI

 

I've this function to get the list of report with API

and I put the list in a asp:dropdownlist

 

can you help me to sort them alfabetically?

 

    Protected Sub GetReport(ByVal index As Integer)
        Dim request As System.Net.WebRequest = TryCast(System.Net.WebRequest.Create(String.Format("{0}/Reports", baseUri)), System.Net.HttpWebRequest)
        request.Method = "GET"
        request.ContentLength = 0
        request.Headers.Add("Authorization", String.Format("Bearer {0}", accessToken.Value))
        Using response = TryCast(request.GetResponse(), System.Net.HttpWebResponse)
            Using reader = New System.IO.StreamReader(response.GetResponseStream())
                Dim Reports As PBIReports = JsonConvert.DeserializeObject(Of PBIReports)(reader.ReadToEnd())

For Each r In Reports.value elencoreport.Items.Add(New ListItem(r.name, r.id)) Next End Using End Using End Sub

 

thanks

Lenny

 

1 ACCEPTED SOLUTION
v-ljerr-msft
Microsoft Employee
Microsoft Employee

Hi @lenny76,

 

Here is a similar thread in which some workarounds are mentioned. Could you go to check if it helps in your scenario?

 

In addition, the code below is for your reference. Smiley Happy

 

Protected Sub GetReport(ByVal index As Integer)
        Dim request As System.Net.WebRequest = TryCast(System.Net.WebRequest.Create(String.Format("{0}/Reports", baseUri)), System.Net.HttpWebRequest)
        request.Method = "GET"
        request.ContentLength = 0
        request.Headers.Add("Authorization", String.Format("Bearer {0}", accessToken.Value))
        Using response = TryCast(request.GetResponse(), System.Net.HttpWebResponse)
            Using reader = New System.IO.StreamReader(response.GetResponseStream())
                Dim Reports As PBIReports = JsonConvert.DeserializeObject(Of PBIReports)(reader.ReadToEnd())

                For Each r In Reports.value
                    elencoreport.Items.Add(New ListItem(r.name, r.id))
                Next
                List<ListItem> items = (from item in elencoreport.Items.Cast<ListItem>()
                                    orderby item.Text
                                    select item).ToList<ListItem>();
                elencoreport.Items.Clear();
                elencoreport.Items.AddRange(items.ToArray());
            End Using
        End Using
    End Sub

 

Regards

View solution in original post

2 REPLIES 2
v-ljerr-msft
Microsoft Employee
Microsoft Employee

Hi @lenny76,

 

Here is a similar thread in which some workarounds are mentioned. Could you go to check if it helps in your scenario?

 

In addition, the code below is for your reference. Smiley Happy

 

Protected Sub GetReport(ByVal index As Integer)
        Dim request As System.Net.WebRequest = TryCast(System.Net.WebRequest.Create(String.Format("{0}/Reports", baseUri)), System.Net.HttpWebRequest)
        request.Method = "GET"
        request.ContentLength = 0
        request.Headers.Add("Authorization", String.Format("Bearer {0}", accessToken.Value))
        Using response = TryCast(request.GetResponse(), System.Net.HttpWebResponse)
            Using reader = New System.IO.StreamReader(response.GetResponseStream())
                Dim Reports As PBIReports = JsonConvert.DeserializeObject(Of PBIReports)(reader.ReadToEnd())

                For Each r In Reports.value
                    elencoreport.Items.Add(New ListItem(r.name, r.id))
                Next
                List<ListItem> items = (from item in elencoreport.Items.Cast<ListItem>()
                                    orderby item.Text
                                    select item).ToList<ListItem>();
                elencoreport.Items.Clear();
                elencoreport.Items.AddRange(items.ToArray());
            End Using
        End Using
    End Sub

 

Regards

THANKS!!!!!!Smiley Happy

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.