views:

1278

answers:

4

Hi,

how do I create a wiki page and add a title, as well as some content in sharepoint (via webservices)?

This is my SOAP message so far:

  <soapenv:Body>
  <soap:UpdateListItems>

    <soap:listName>Cooking Wiki</soap:listName>

    <soap:updates>
     <Batch OnError="Continue">
      <Method ID="1" Cmd="New">   
       <Field Name="WikiField">Mix two eggs and a cup of milk.</Field>
      </Method>
     </Batch>
    </soap:updates>

   </soap:UpdateListItems>
  </soapenv:Body>

It creates a new page, but it has no content and no title.

+4  A: 

Grab a copy of SharePoint Manager it can show you heaps of interesting info.

you want the Name field (it includes the ".aspx"). The title field is not relevant in a wiki (blank), pages are indexed by thier name instead.

--update--

Using the copy.asmx allows you to upload a new document. The template page is a page that has been downloaded previously (it stores no information, equivalent to a layout page).

private byte[] GetTemplatePage()
{
    FileStream fs = new FileStream("templatePage.aspx", FileMode.Open);
    byte[] fileContents = new byte[(int)fs.Length];
    fs.Read(fileContents, 0, (int)fs.Length);

    fs.Close();
    return fileContents;
}

private void UploadDoc(string pageName)
{
    byte[] wikiBytes = GetTemplatePage();

    string dest = "http://[website]/wiki/Wiki%20Pages/" + pageName + ".aspx";
    string[] destinationUrlArray = new string[] { dest };

    IntranetCopy.Copy copyService = new IntranetCopy.Copy();
    copyService.UseDefaultCredentials = true;
    copyService.Url = "http://[website]/wiki/_vti_bin/copy.asmx";

    IntranetCopy.FieldInformation fieldInfo = new IntranetCopy.FieldInformation();
    IntranetCopy.FieldInformation[] fields = { fieldInfo };

    IntranetCopy.CopyResult[] resultsArray;
    copyService.Timeout = 600000;

    uint documentId = copyService.CopyIntoItems(dest, destinationUrlArray, fields, wikiBytes, out resultsArray);

}

Then you can call the lists.asmx to update the wikifield. Note: I have not figure out how to rename a document once it has been uploaded using webservices.

Nat
I've already installed the Sharepoint Manager and tried almost every property: no solution. :-(
Stefan
Yeah, looks like the wiki is a pretty special case of a document library.
Nat
+2  A: 

Check out this page:

Creating Content on SharePoint Wikis via Web Services

Kevin Davis
Thanks. I know it already. I've even done a stopgap with the CopyService, with is mentioned in the article. But this is not a proper solution for me, because I need to create the pages from scratch.
Stefan
+1  A: 

Dan Winter wrote a fantastic application that I think could provide some sample code, take a look at it here:

WikiMigrator

Or for more information, read his comprehensive blog posts.

Daniel McPherson
Thanks, I've already used it to understand what's going on in the SOAP calls.
Stefan
+1  A: 

If nothing else is working you should develop your own web service to provide this feature. The out-of-the-box options are notoriously limited in functionality but there is nothing stopping you from adding to them.

I would wrap Nat's solution into the web service code.

Alex Angas
Sadly it's not an option to write my own web service, because the solution has to work on generic Sharepoint servers.
Stefan