Search This Blog


Create Pages Using Object Model

Following example shows how to create a cutom HTML page using WSS Object model .

Step 1.Create a New console application
Step 2.Add a reference of Microsoft.Sharepoint.dll
Step 3 .Write the following code
using System;
using System.IO;
using Microsoft.SharePoint;

namespace CreateNewSitePage {
class Program {
static void Main() {

string sitePath = "http://manab:36069/sites/DevSite";
SPSite siteCollection = new SPSite(sitePath);
SPWeb site = siteCollection.RootWeb;

// write out new page in memory stream
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.WriteLine("<html><body >");
writer.WriteLine("Hello, World");
writer.WriteLine("</body></html >");

// add new page to site
site.Files.Add("hello.htm", stream);

Step 4.Now go to your sharepoint site and type the url as follows

You will get the output as follows

No comments: