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'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)
                {

                    Console.WriteLine(list.Title);
                    System.Console.ReadLine();
                }
            }
        }
    }
}

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
add comment

2 Answers 2

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! –  Bruno Ferreira 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? –  Bruno Ferreira 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?? –  Bruno Ferreira Feb 10 '12 at 11:46
    
I think you should create event receiver for ItemAdded event. –  Alex Boev Feb 10 '12 at 11:52
add comment

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
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.