The page published in the moss page library yesterday is automatically saved to the root directory, even if you created it in a subdirectory.
So I found this article at jianyi: [original address]
The moss page publishing function keeps the page under the directory of the following. How can I create a page under a sub-folder?
No relevant information was found on the Internet, so I had to change the systemCode.
The publishing system page is: _ layouts/createpage. aspx.
Add the following code to createpage. aspx:
<% @ Import namespace = " Microsoft. SharePoint " %>
<% @ Import namespace = " Microsoft. Sharepoint. Publishing " %>
< Script runat = " Server " >
String _ Folderurl;
Int _ Layoutid;
String _ Pagename;
Void Createpagetocurrentfolder ( Object Sender, eventargs E)
{
_ Folderurl = "" + Request. querystring [ " Rootfolder " ];
_ Layoutid = Convert. toint32 (dropdownlist. selectedvalue );
_ Pagename = This . Urlnametextbox. Text. Trim () + " . Aspx " ;
Createpage ();
}
Pagelayout getpagelayout (publishingweb, Int Layoutid)
{
Pagelayout [] layouts = Publishingweb. getavailablepagelayouts ();
Foreach (Pagelayout L In Layouts)
{
If(L. listitem. ID=Layoutid){
ReturnL;
}
}
Return Null ;
}
Void Createpage ()
{ // Bool o = publishingweb. ispublishingweb (base. Web );
Publishingweb = Publishingweb. getpublishingweb ( Base . Web );
Publishingsite site = New Publishingsite ( Base . Web. Site );
// If (publishingweb. getpublishingpages () ["pages/my1.aspx"] = NULL)
// Create the default page // Spcontenttypeid contenttypeid = new spcontenttypeid ("batch ");
// Pagelayout [] layouts = publishingweb. getavailablepagelayouts ();
// Pagelayout selectedpagelayout = layouts [0];
Pagelayout selectedpagelayout = Getpagelayout (publishingweb, _ layoutid );
String Fullpagepath = _ Pagename;
If (_ Folderurl ! = "" )
Fullpagepath = _ Folderurl + " / " + _ Pagename;
Publishingpage Newpage = Publishingweb. getpublishingpages ( 1 ). Add (fullpagepath, selectedpagelayout );
// Newpage. Title = This. urlnametextbox. Text. Trim ();
Newpage. Update ();
Splistitem item = Publishingweb. pageslist. getitembyid (Newpage. listitem. ID );
Item [ " Title " ] = This . Urlnametextbox. Text. Trim ();
// Item ["topic"] = This. urlnametextbox. Text. Trim ();
Item. Update ();
// Set the default page
Spfile welcomefile = Base . Web. GetFile (Newpage. url );
// Publishingweb. defaultpage = welcomefile;
String Weburl = Publishingweb. url;
If ( ! Weburl. endswith ( " / " ))
Weburl + = " / " ;
Page. response. Redirect (weburl + Newpage. url + " ? ControlMode = edit & displaymode = Design " );
// Publishingweb. Update ();
}
</ Script >
Modify the Save button event:
< ASP: button runat = " Server " Class = " MS-buttonheightwidth " Onclick = " Createpagetocurrentfolder "
Text = " <% $ Resources: CMS, createpage_createbutton %> " ID = " Buttoncreatepage " Accesskey = " <% $ Resources: CMS, createbutton_accesskey %> " />