To add an item to a document library, use SPFileCollection.Add()

will man mit der powershell in einer wiki ein dokument hinzufügen, so kann man dies nicht Microsoft.SharePoint.SPListItem Add() erledigen, weil es sich bei der wiki ja um eine document library handelt (die wiki seiten sind nichts anderes als aspx dokumente!) – daher schlägt folgendes fehl:

# vars

$SiteName = “http://mosstest/”
$WebName = “/Wiki/”
$ListName = “Wiki Pages”

# connect to sharepoint and open the wiki list

$mossSite = new-object Microsoft.SharePoint.SPSite($SiteName);
$mossWeb = $MossSite.AllWebs[$WebName];
$mossList = $MossWeb.Lists[$ListName];

“Got List…”

# try to add a new item

$item = $mossList.Items.Add()
$item.Update();

Exception calling “Update” with “0″ argument(s): “To add an item to a document library, use SPFileCollection.Add()”
At line:1 char:13
+ $item.Update( <<<< );

die fehlermeldung ist eigentlich eindeutig; wie macht man es nun richtig? so:

# vars

$SiteName = “http://mosstest/”
$WebName = “/Wiki/”
$ListName = “Wiki Pages”

# connect to sharepoint and open the wiki list

$mossSite = new-object Microsoft.SharePoint.SPSite($SiteName);
$mossWeb = $MossSite.AllWebs[$WebName];
$mossList = $MossWeb.Lists[$ListName];

“Got List…”

# try to add a new item

[byte[]]$mydata = “hipslu was here”.ToCharArray(); # dummydata
$newFile = $mossList.RootFolder.Files.Add(“newwikientry.aspx”, $mydata);

allerdings wird in diesem beispiel natürlich keine richtige wiki seite erstellt – für einen ernsthafen einsatz muss die variable $mydata einen entsprechend sinnvollen inhalt haben (oder man kopiert den wiki eintrag von woanders her)

Related posts:

  1. New/Edit/Display Forms anpassen?
  2. Split DNS? you could do better…
  3. Windows 7 Keyboard Shortcuts

Related posts brought to you by Yet Another Related Posts Plugin.

Make a Comment

One Response to “To add an item to a document library, use SPFileCollection.Add()”

RSS Feed for konfabulieren Comments RSS Feed

Is it javaScript language?
Oh,then,what about the C#.net to do this?thank you.

leaf wrote on September 20, 2008 @ 04:07 (in other words: 8 months, 2 weeks after the fact)

leaf

Where's The Comment Form?

Liked it here?
klick here to open a random post - or have a look at this: