0

i am new to sharepoint. Can someone tell me how to remove duplicate webapplication names from my code below:

SPFarm farm = SPFarm.Local;
                SPWebService webser = farm.Services.GetValue<SPWebService>("");
                DataTable dt = new DataTable();
                dt.Columns.Add("Name", typeof(string));
                dt.Columns.Add("Port Numbers", typeof(string));

                foreach (SPWebApplication spwebApp in webser.WebApplications)
                {
                    foreach (SPSite site in spwebApp.Sites)
                    {
                        DataRow dr = dt.NewRow();
                        dr[0] = site.WebApplication.Name;
                        dr[1] = site.Port;
                        dt.Rows.Add(dr);
                    }
                }

                this.GridView1.DataSource = dt;
                this.GridView1.DataBind();

Help Highly Appreciated!

i want to display only one name with one port number in the grid. for instance if there are five sites on web application port no. 2222 it displays 5 times webapplication name with port number 2222. I want it only once.

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
S. Majhi
  • 35
  • 1
  • 5
  • Got the answer here: http://stackoverflow.com/questions/1199176/how-to-select-distinct-values-from-datatable – S. Majhi Dec 31 '12 at 04:53

1 Answers1

1
DataView view = new DataView(dt);
dt = view.ToTable(true, "Name", "Port Numbers");
Greg Sansom
  • 20,442
  • 6
  • 58
  • 76