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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s