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

Forums / Developing with Sitefinity / List of Pages for an Owner

List of Pages for an Owner

4 posts, 0 answered
  1. mattc
    mattc avatar
    105 posts
    Registered:
    11 Aug 2007
    01 May 2009
    Link to this post
    Hello

    I'm starting to get into using the API to write user controls to migreate an application to Sitefinity.

    The application allows users to create several pages. So I have got the code working so it creates a page, sets the properties including the owner, applies a template and theme and saves it.

    What I need to do now is understand how to get lists of existing pages. I want to be able to check that a page with the propesed name has not already been created, then get a list of pages for a certain user account (ie all pages belonging to an owner)

    I'm having real trouble finding any documentation resources on this, have been searching the forums and developer documentation but if nobody has asked the question in the forum all I often find is the API documentation which just lists the bare bones of the properties and methods.

    Many thanks

    Matt
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    01 May 2009
    Link to this post
    Hello mattc,

    Here are two samples that illustrates working with sitefinity's api

    Create a new page:

     CmsManager manager = new CmsManager(); 
            IList listOfPages = manager.GetPages(); 
            string newPageName = "MyNewPage"
            foreach (ICmsPage page in listOfPages) 
            { 
                if (page.Name.Equals(newPageName)) 
                    throw new Exception("There is a page with the same name"); 
            } 
            IPage newpage = manager.CreatePage(newPageName); 
            manager.SavePage(newpage); 

    Get pages that belongs to a certain owner

            CmsManager manager = new CmsManager(); 
            IList listOfPages = manager.GetPages(); 
            foreach (ICmsPage page in listOfPages) 
            { 
                if (page.Owner == "admin"
                    Response.Write(page.Owner + "-" + page.Status + "-" + page.Name + "<br />"); 
            } 


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. mattc
    mattc avatar
    105 posts
    Registered:
    11 Aug 2007
    01 May 2009
    Link to this post
    Hi Ivan

    Many thanks for your fast reply, those both work fine. Was wondering if there were some specific methods to get these answers but looping through works fine.

    I'm sure I will have more questions!

    Thanks

    Matt
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    01 May 2009
    Link to this post
    Hello mattc,

    You may find the following section of our developer manual useful Working with Pages Programmatically

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
4 posts, 0 answered