Results 1 to 13 of 13

Thread: [2008] Reordering [UNRESOLVED]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    592

    Question [2008] Reordering [UNRESOLVED]

    I am using Microsoft.Web.Administration to create NEW websites programatically.

    How do i change all ID's starting from zero? Currently i have about 100 websites and they are ordered like following:



    1, 2, 4, 18, 200, 1234, 232324, 2455344 etc. etc.

    And i want them ordered like this: 1, 2, 3, 4, 5, 6, 7, ... etc. up to 100.

    This question doesn't have to refer IIS and the Administration class directly.
    I just need to change the id like you change the values into database or array/arraylist or generic list.

    Means the value with 1234 should be 6 if six is not already taken or 18 should be 3 etc.


    Thanks
    Last edited by selanec; Apr 6th, 2009 at 04:00 AM.

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    592

    Re: [2008] Reordering

    It would be best if i can set them all to zero and then start from 1.

    Code:
    For each site As Site in Manager.Sites
       i += 1
       site.Id = i
    Next
    but unfortunately it is not possible as IIS doesn't support this approach (no multiple sites with same ID)
    Last edited by selanec; Mar 7th, 2009 at 05:40 PM.

  3. #3
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2008] Reordering

    I would loop through all of the sites and add them to a list of type integer.

    Code:
            Dim l As List(Of Integer) = New List(Of Integer)
    
            'Add all of your sites to a list, this is just sample data
            l.Add(1)
            l.Add(2)
            l.Add(450)
            l.Add(693)
            l.Add(44)
            l.Add(5)
    
            ' sort the list
            l.Sort()
    
            Dim i As Integer = 1
            For Each listitem As Integer In l
                If i <> listitem Then
                    'update site with index of listitem to i
                End If
                i += 1
            Next

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    592

    Re: [2008] Reordering

    hmm it's not that easy. let me test smtg

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    592

    Re: [2008] Reordering

    Omg it really took me a long time to response. Sorry for that.

    Ok your algorithm looks just fine to me and i tested it using an array.

    However, now i have another problem which is how to update the site ID.

    I am using Microsoft.Web.Administration library on WIn Server 2k8 with IIS7.

    i cannot manage to edit and commit changes the existing sites.

    Dim serverManager As ServerManager = New ServerManager

    For each site As Site in serverManager.Sites
    site.Id = i
    Next

    The code above won't work as you can guess. Any idea how do i work it out?

    I couldn't find any code snippet for editing site's attributes on the net.

    Thanks for any further help

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    592

    Re: [2008] Reordering

    *bump*

  7. #7
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2008] Reordering

    If you increment i each time through the loop, it should work just fine.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    592

    Re: [2008] Reordering

    Well i get an exception if i do that.

    System.Runtime.InteropServices.COMException: Invalid index. (Exception from HRESULT: 0x80070585)

    Test Code:


    Code:
    Dim serverMgr As ServerManager = New ServerManager
    Dim sites As SiteCollection = serverMgr.Sites
    
            For Each sit As Site In sites
                If sit.ApplicationDefaults("ApplicationPool").ToString <> "DefaultAppPool" Then
                    sit.SetAttributeValue("ApplicationPool", "DefaultAppPool")
                    'sit.ApplicationDefaults("ApplicationPool") = "DefaultAppPool" --- i tried this as well
                    serverMgr.CommitChanges()                
                End If
            Next
    serverMgr.Dispose()
    I get the same error if i try to set up the ID of the site(s).

    Thanks for any further help

  9. #9
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2008] Reordering

    Why don't you use two loops. One to populate the list I talked about in my first post and then a second loop to do the updates.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    592

    Re: [2008] Reordering

    Well i am planning to do that but first i have to change the App Pool.
    Then i will use the loop to set the ID's.

    But i can't manage it ... i couldn't figure out what is the code for updating the attributes of the sites and applications.

    Thank you for the help. It's much appreciated.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    592

    Re: [2008] Reordering

    * bump *

    Sorry guys but i really cannot come with anything useful ... google is useless for me.

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    592

    Re: [2008] Reordering

    Code:
    Dim l As List(Of Integer) = New List(Of Integer)
    
            'Add all of your sites to a list, this is just sample data
            l.Add(1)
            l.Add(2)
            l.Add(450)
            l.Add(693)
            l.Add(44)
            l.Add(5)
    
            ' sort the list
            l.Sort()
    
            Dim i As Integer = 1
            For Each listitem As Integer In l
                If i <> listitem AndAlso Not l.Contains(i) Then
                    MessageBox.Show(i)
                End If
                i += 1
            Next
    This did the trick! Thanks a lot

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    592

    Re: [2008] Reordering [UNRESOLVED]

    Hmm for some reason the code below won't work as expected.
    Code:
           Dim intList As List(Of Integer) = New List(Of Integer)
    
            For Each site As Site In sites
                intList.Add(site.Id)
            Next
            intList.Sort()
    
            Dim i As Integer = 1
            For Each item As Integer In intList
                If i <> item And Not intList.Contains(i) Then
                    For Each sit As Site In sites
                        If item = sit.Id Then
                            sit.Id = i
                            serverMgr.CommitChanges()
                            i += 1
                        End If
                    Next
                End If
            Next
    Am i missing something? It seems that intList.Contains(i) always return true while it shouldn't.
    Last edited by selanec; Apr 6th, 2009 at 04:01 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width