SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm are working on a SharePoint Site where I have created lot of Lists. In my example , I created a simple automatically way (by code) to print out each List into my site:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace EsercizioSP
    class Program
        static void Main(string[] args)
            string SiteURL = "http://sp2010dev/sites/MySite/";
            using (SPSite sc = new SPSite(SiteURL))
                SPWeb site  = sc.RootWeb;
                foreach (SPList list  in site.Lists)


Now I've been looking for an object SPPage or SiPge or something like this, that allows me to to print out every site page into the webSite. Does anybody know if a such object exist?

share|improve this question

What do you mean as "site page"? There's no dedicated object "SPPage" or something like that. THere are pages in document libraries (such as "Pages" library) - they are simple list items (SPListItem) with specific content type and SPFile conntected to it as SPListItem.File.

share|improve this answer
Thanks a lot, very useful! – hello B Feb 10 '12 at 10:05
Ok... It work. But now my question is: If I should create an Webpage.aspx into a list by code, witch object should I use? – hello B Feb 10 '12 at 11:12
I don't know ideally right way to do it but I made it simply. I created manually a clear page with desired layout in library and then copied it via SPListItem.CopyTo method each time I was needed to create new page (in my case it was webpart pages). – Alex Boev Feb 10 '12 at 11:23
Thanks. Only one more question. I got simple List. and I need to create some way that , each time I insert a new item inside this List, by an Event, will trigger some method that will create a new WebpartPage with data from the new Item inserted..Do you know which Event should be that?? – hello B Feb 10 '12 at 11:46
I think you should create event receiver for ItemAdded event. – Alex Boev Feb 10 '12 at 11:52

Next step is for each SPList to try cast it to a SPDocumentLibrary. If cast is ok then you can start iterate (recursive) using SPList.RootFolder.Files and SPList.RootFolder.SubFolders.

share|improve this answer

Your Answer


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.