+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Add additional url from code

Add additional url from code

4 posts, 1 answered
  1. Constantin Aparaschivei
    Constantin Aparaschivei avatar
    27 posts
    Registered:
    10 Nov 2009
    18 Mar 2010
    Link to this post
    Hi, I am trying to add additional url for a page from code.

    Here is my code:

            // create a new instance of CmsManager
            CmsManager cmsManager = new CmsManager();
            // get all pages
            IList allPages = cmsManager.GetPages();
            
            foreach (ICmsPage oPage in allPages) {

                if (oPage.Name == "test")
                    oPage.AddUrl("~/test2.aspx");
            }


    I get this error on the line with AddUrl method: IOdbClass must be joined to a transaction

    Am I doing something wrong?

    I am using sitefinity 3.6.1861

    Thanks.
  2. Constantin Aparaschivei
    Constantin Aparaschivei avatar
    27 posts
    Registered:
    10 Nov 2009
    18 Mar 2010
    Link to this post
    Probably I should mention that my website had localization enabled, but now it is disabled. It is possible to have content from other languages in the db.
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    18 Mar 2010
    Link to this post
    Hi Constantin Aparaschivei,

    Below is a sample code that illustrates how to add an additional url

    var cmsManager = new CmsManager();
    //get your page
    Guid pageID = new Guid("40b75e9d-4205-45aa-89c6-db43373ce41e");
    ICmsPage cmsPage = (ICmsPage)cmsManager.GetPage(pageID, true);
    //add url to this page
    cmsPage.AddUrl("~/someurl.aspx");
    //save the page
    cmsManager.SavePage(cmsPage);

    You need to get the pages you want to modify using GetPage(ID, true) method before making any transactions ( say saving/updating the object)

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
    Answered
  4. Constantin Aparaschivei
    Constantin Aparaschivei avatar
    27 posts
    Registered:
    10 Nov 2009
    18 Mar 2010
    Link to this post
    Thanks for your fast response. It works, of course :)
Register for webinar
4 posts, 1 answered