locked
Get a specific Site in SiteCollection RRS feed

  • Question

  • User-373518479 posted

    Hi All,

    I am trying to get a specific site in a sitecollection and the code is failing me so far. Can you please show how?

    I could get the default website using this:

    Dim SvrMgr As New ServerManager
    Dim s As SiteCollection = SvrMgr.Sites
    Dim siteName As String = System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName()
    Dim siteIndex As Integer = System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteID
    Dim ss As Site = s.FirstOrDefault

    Now, I want to get a specific site on IIS named as "Mywebsite.com". How can I do that?

    Regards,

    Ahmad

    Thursday, November 29, 2018 10:46 AM

All replies

  • User-821857111 posted

    Dim ss As Site = s.FirstOrDefault(function(s) s.Name = "Mywebsite.com")

    Thursday, November 29, 2018 12:54 PM
  • User-271186128 posted

    Hi Ahmad,

    You could also use where clause to filter the site. Code as below:

    Dim ss As Site = s.Where(function(s) s.Name = "Mywebsite.com").FirstOrDefault()

    Best regards,
    Dillion

    Friday, November 30, 2018 3:14 AM