The SPWeb object for a site exposes a Files property with a public Add method that allows you to add new site pages. There is an overloaded version of the Add method that allows you pass a stream object with the content of the new page. The following example demonstrates writing the contents of a new page to a Memory Stream object and then using it to create a new site page named Hello.htm.
//write out new page in memory stream.
MemoryStream stream=new MemoryStream();
StreamWriter writer=new StreamWriter(stream);
writer.WriteLine("");
writer.WriteLine("Hello, world");
writer.WriteLine("");
writer.Flush();
//add new page to site
SPWeb site=SPContext.Current.Web;
site.Files.Add("hello.htm",stream);
Let me know if you have any question.
Thanks,
Sanjay
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment