Cs&#233&#59;ffai Norbert

Hi,

I would like to post on a webpage what i wrote in my wiki page. But if i use my wiki page's url: http://localhost/wiki/Wiki%20Pages/Home.aspx then the whole page is loaded and not only the content of the wiki. Can you tell me how can i read the content of the wiki page from visual studio or sharepoint designer

Thanx



Re: Internet Explorer Web Development How to get Wiki Content from a Sharepoint Wiki Site

Erik Noren

Hi,

I had a similar task to do. There is a community site which gave me a big clue to the reading and writing of content to SharePoint Wiki Pages. Have a look at:

http://www.codeplex.com/CKS/Release/ProjectReleases.aspx ReleaseId=4623

There is source code which might help. See the FlexWikiImporter project source. The key is to treak the Wiki pages like a SPList and access the content at the index "WikiField". This will let you get and set data. The caveat with getting data being that it comes back wrapped in div tags. Additionally, each paragraph of text is also wrapped in another set of div tags. I haven't investigated to see if there is a field to retrieve the plain text that was inserted.

The basic psuedo-code is to do something like:

SPSite yourSite = new SPSite("http://your_sp_host/your_wiki_site/Home.aspx");

SPWeb projectWeb = yourSite.OpenWeb();

SPList wikiLibrary = projectWeb.Lists["Wiki Pages"]; //Wiki Pages is the default collection name for a wiki site created using the wiki template in English localization.

string wikiFileURL = wikiLibrary.RootFolder.Url + "/" + name_of_wiki_topic + ".aspx";

SPFile wikiFile = wikiLibary.RootFolder.Files[wikiFileURL]; //this will fail if the topic has not yet been created. Wrap in a try..catch to catch error when the file doesn't exist.

SPListItem wikiEntry = wikiFile.Item;

string myContent = wikiEntry["WikiField"].ToString();

This obviously excludes proper error catching and doesn't include the code to create a new topic or insert data (hint: it's very similar - you can assign to wikiEntry["WikiField"] as well as read from it.)

Hope this helps get you in the right direction.

Happy Coding and Thanks to the people at the Community Kit for SharePoint for pointing me in the right direction!

-Erik