Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a meetings list, when a new event is created a subsite is created with an specific format. The list allows to change the date of the events, but when this happens the name of the subsite and its url are not changed.

I need to be able to do this by code, so I am coding an ItemUpdated event. However the Url Property is readonly. How can I change this by code? I did using the interface and its possible.

 public override void ItemUpdated(SPItemEventProperties properties)
        {
            Logger.LogDebug("MeetingCalendarEvents", "ItemUpdated(SPItemEventProperties properties)", "BEGIN");
            base.ItemUpdated(properties);
            try
            {
                base.EventFiringEnabled = false;
                SPSite site = properties.Web.Site;                
                SPWeb web = site.AllWebs[properties.BeforeProperties["Title"].ToString()];

                web.AllowUnsafeUpdates = true;
                web.Title = properties.AfterProperties["Title"].ToString();
                web.url = properties.AfterProperties["Title"].ToString(); //wont compile
                web.Update();

                web.AllowUnsafeUpdates = false;

            }
            catch (Exception ex)
            {
                Logger.LogError("MeetingCalendarEvents", "ItemUpdated(SPItemEventProperties properties)", ex);
                properties.ErrorMessage = ex.Message;
                properties.Cancel = true;
            }
            finally
            {
                base.EventFiringEnabled = true;
            }
            Logger.LogDebug("MeetingCalendarEvents", "ItemUpdated(SPItemEventProperties properties)", "END");
        }
share|improve this question
    
Repost of stackoverflow.com/questions/2490767/… –  RJ Cuthbertson Aug 2 '12 at 15:07
add comment

2 Answers

up vote 1 down vote accepted

Try SPWeb.ServerRelativeUrl for re-parenting webs.

share|improve this answer
add comment

I think you can set the SPWeb.Name property instead of SPWeb.Url. SPWeb.Name is an empty string if it is the root web.

share|improve this answer
    
so if I change the name the url will change? –  L.V. Sharepoint Architect Aug 2 '12 at 12:40
    
Yes, that should do the trick. –  marco Aug 2 '12 at 12:41
    
This is the same solution presented in stackoverflow.com/questions/2490767/… I'm surprised by this. I can see this working on new site creation, but I'm curious about whether or not this alters existing sites. I'd like to know what you find. –  RJ Cuthbertson Aug 2 '12 at 15:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.