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

The following code iterates through the pages in our wiki then tries to add a new one. It adds fine but the PageLayout is changed to null after the page is added. Is there any way to set the PageLayout on a new page using web service calls? I'm trying to avoid using the Microsoft.Sharepoint library.

        ServiceReference1.HomeDataContext home = new HomeDataContext(new Uri("http://utah:82/_vti_bin/ListData.svc"));            
        home.Credentials = System.Net.CredentialCache.DefaultCredentials;

        foreach (var Page in home.Pages)
        {
            this.TxtActivity.AppendText("Page: " + Page.Name + Environment.NewLine);
            int acnt = 0;
        }

        PagesItem page = new PagesItem();
        page.ApprovalStatus = "0";
        page.Name = "TestCodePage1.aspx";
        page.ContentType = "Enterprise Wiki Page";            
        page.ContentTypeID = "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39004C1F8B46085B4D22B1CDC3DE08CFFB9C0004D854AA15019B4CBC2BCC51663D50F6";
        page.Path = "/Pages";            
        page.Title = "Testy Code Pagey1";
        page.PageLayout = @"http://utah:82/_catalogs/masterpage/EnterpriseWiki.aspx, Basic Page";

        home.AddToPages(page);

        home.SetSaveStream(page, new MemoryStream(Encoding.UTF8.GetBytes("Test code testy. ")), false, page.ContentType, page.Path + @"\" + page.Name);
        home.SaveChanges();            
share|improve this question
add comment

1 Answer

There are at least two ways you can use a Web service to create a new wiki page.

The first is to use the Copy.CopyIntoItems service to make a copy of the raw ASPX file. Using this approach, you will actually be able to modify the contents of the file "on the fly" before saving back into SharePoint.

The second is to use the Lists.AddWikiPage service to add a new page to a wiki library. Using this approach, you only have to specify the contents of the wiki and do not have to worry about all the other ASPX file content.

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.