Logo Home   Downloads   Up to Bluedog Limited
How to programmatically create a ghosted web part page
Posted on 4/10/2005 9:42 PM by Maurice Prather

Every once in while, you learn something new even though you’ve been working with a particular technology for quite some time.  Today’s post is courtesy of Kimmo (and, yes, he feels guilt for not having blogged yet).  A couple months ago, he asked the age old question…

 

Kimmo: “Is there a way to programmatically create a ghosted page?”

 

My reply: “Unfortunately, there is no way to programmatically create ghosted pages.

 

Bear in mind that has been my answer for the past few years.  In fact, Kimmo went on to ask “How about using a http post like spcf.aspx does?”  That was logical alternative, but not elegant in my opinion.  You could create an http post and mimic the page behavior.  I was correct in saying that the OM did not *specifically* offer a means to create a ghosted page, but what Kimmo had in mind was completely different than what I had interpreted by his second question.  Two weeks later, Kimmo presented me with a code snippet that completely changed how I would forever more respond to the question above.  The solution?  It all lies with SPWeb.ProcessBatchData.

 

Here’s the code that will allow you to create a ghosted page…

 

        using (SPSite site = new SPSite ("http://redhorse")) {

          using (SPWeb web = site.OpenWeb()) {

           

            SPList list = web.Lists ["Shared Documents"];

           

            string postInformation =

              "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +     

              "<Method>" +

                "<SetList Scope=\"Request\">" + list.ID + "</SetList>" +

                "<SetVar Name=\"ID\">New</SetVar>" +

                "<SetVar Name=\"Cmd\">NewWebPage</SetVar>" +

                "<SetVar Name=\"Type\">WebPartPage</SetVar>" +

                "<SetVar Name=\"WebPartPageTemplate\">2</SetVar>" +

                "<SetVar Name=\"Title\">MyWebPartPageName</SetVar>" +

                "<SetVar Name=\"Overwrite\">true</SetVar>" +

              "</Method>";

             

            string processBatch = web.ProcessBatchData(postInformation);

           

            // Display the results...

            Console.WriteLine(processBatch);

            Console.ReadLine ();

           

          }

        }

 

The yellow highlights are the variables that represent options on the New Web Part Page.  Nice surprise – the OM does in fact allow you to create ghosted pages. :)

-Maurice

Add a hidden page to Multi-Page meeting WSS site
Hi
I am new to WSS world. I created a Multi-Page Project site. The user wants to add aditional web pages to this site however does not want those pages to show as a tab on the top. So it should be kind of hidden but linked from the content on the site.
One way I tried was to create a child site under this site, but then I loose the look and feel of the original site. I have to add many such pages to this site. Also the web parts referencing lists do not export very well in the child sites.
Any suggestions??? Why does this not give me that option to add web pages like in other team sites?
 
Thanks
Novice
 
NoviceWSSuser @ 4/19/2005 8:40 PM
re: How to programmatically create a ghosted web part page
Thanks! This is really great.
 
<Todd />
Todd Bleeker @ 4/26/2005 4:18 AM
re: How to programmatically create a ghosted web part page
Novice,
 
Just directly access the "Create" page by appending "_layouts/1033/create.aspx" to your site's url.  This will allow you create doc libs and pages that will live within the meeting site.
 
Anonymous User @ 4/28/2005 7:40 PM
re: How to programmatically create a ghosted web part page
Hi Maurice,
 
What do you mean by a ghosted page... If you create a page this way, you don't get a copy of the page in the database? The only copy is in the document library itself?
Serge van den Oever [Macaw] @ 6/6/2005 2:21 PM
re: How to programmatically create a ghosted web part page
Ghosted pages are discussed in the following posts:

If you read the first article, this post will make much more sense.  :)

Maurice Prather @ 6/6/2005 3:29 PM
re: How to programmatically create a ghosted web part page
This is very helpful thank you.  I am an idiot, I am also buiding a sharepoint site with Frontpage.  Are you saying that if I run the SPWeb.ProcessBatchData script on my site, that I will be able to re-Ghost my site?  Or does this just apply to specific situations, like for specific web parts? - thank you
G-Man @ 7/25/2005 4:33 PM
re: How to programmatically create a ghosted web part page
G-Man:
 
The code described in this post is used to create a ghosted page.  If you follow the links in previous comments, you'll see that "ghosted" and "unghosted" refer to page states and *not* the state of a site or a web part.
 
Maurice Prather @ 8/2/2005 12:56 AM
How to remove or change top menu in Sharepoint the Home ...
Faz @ 8/18/2005 2:38 AM
re: How to programmatically create a ghosted web part page
Maurice,
 
This is great thanks!
 
Question: Can you control which document library the ghosted pages lives in depending on the doc library you opened in the following statement?
 
SPList list = web.Lists ["Shared Documents"];
ben @ 3/13/2006 4:08 PM
re: How to programmatically create a ghosted web part page
Ben: Yup.
Maurice Prather @ 3/14/2006 10:58 AM
It can be done, but it's not conventional programming
Kimmo, there is hope yet. We've figured out that you can programmatically create ghosted pages by using FrontPage RPC. I based my code on Pavan: http://blogs.msdn.com/pavankumar/ He uses fpRPC for moveing documents from doclib to doclib with it's metadata. Frontpage actually uses an other method called "move document". It isn't documented by Microsoft, but they do tell you it exists at: http://msdn2.microsoft.com/en-us/library/ms954084.aspx It is however document under SPS v3, but it does work for v2(2003). The documentation is here: http://msdn2.microsoft.com/en-us/library/ms440627.aspx Using this method, I've created a version of pavankumar's code wich can create a copy of a aspx page (i.e. default.aspx) wich is ghosted. Ghosthunter proved as much. Tips: * Don't use validateWelcomeNames * docopy=TRUE * url_list=[] (an empty array to indicate the root af the site/web)
Just another freak @ 5/14/2007 11:09 AM
re: How to programmatically create a ghosted web part page
Hi Maurice
 
Is it possible to set value for content type via ProcessBatchData for ghosted page?
 
I have few content type based on BasicPage or WebPartPage associated with same library or document folder and I would like to set the content type as well.
 
Cheers
admireable
admireable @ 12/1/2007 2:37 AM
Microsoft Certified Master
Are you looking for a team of SharePoint experts?
ShareSquared can help ... drop us a note.
 
 
ShareSquared, Inc.
MVP Logo
Keyword Search
 
View by category
 

Disclaimer:
The contents of this site represent thoughts and opinions of the authors , not those of anyone else - such as past, present and future employers.  This a forum of the exchange of ideas centered on SharePoint technologies.  It is not a support channel.  :)

Copyright © 2004-2009 BluedogLimited.com. All rights reserved.