SharePoint – Add a page directly to a sharepoint site

The following is the code from a feature receiver event.

This allows a page to be added to a sharepoint site without using a page library.

public override void FeatureActivated(SPFeatureReceiverProperties properties)

{

    SPWeb web = properties.Feature.Parent as SPWeb;

 

    FileStream fStream = File.OpenRead(properties.Definition.RootDirectory + \NewPage.aspx);

 

Web.AllowUnsafeUpdates = true;

 

SPFolder folder = web.GetFolder(“”);

 

Folder.Files.Add(“NewPage.aspx”, fStream);

 

fStream.Close();


}

Leave a comment