4

I have a custom definition for a document library and I am trying to rename documents within the library using only the out of the box web services. Having defined a view with the "Name" field supplied and trying the "LinkFilename", my calls to rename a file are respectively returning a failure or ignoring the new value.

How do I rename a file using the SharePoint web services?

Alex Angas
  • 59,219
  • 41
  • 137
  • 210
Nat
  • 14,175
  • 5
  • 41
  • 64

2 Answers2

11

Use the Lists.UpdateListItems web method. The XML request should look like:

<Batch OnError="Continue" PreCalc="TRUE" ListVersion="0">
   <Method ID="1" Cmd="Update">

      <!-- List item ID of document -->
      <Field Name="ID">2</Field>

      <!-- Full URL to document -->
      <Field Name="FileRef">http://Server/FullUrl/File.doc</Field>

      <!-- New filename -->
      <Field Name="BaseName">NewName</Field>

   </Method>
</Batch>
Alex Angas
  • 59,219
  • 41
  • 137
  • 210
  • Hmmm, that would seem to be the case, I would probably to change the "name" property of the underlying list item though. My experiment with the MoveTo, kinda puts the file into some special SharePoint file purgatory. (i.e. not visible to web front end). I am slightly "over" these little "SharePoint suprises". – Nat Jun 15 '09 at 21:30
  • Is FileRef the old url or the new one? Does it look the record up solely by ID? – Scott Stafford Sep 11 '13 at 14:40
  • @ScottStafford FileRef is the old URL. I don't know the inner workings of what SharePoint is doing but I would expect both ID and FileRef need to match. – Alex Angas Sep 12 '13 at 01:43
0

You should be able to use UpdateListItems. Here's an example.

Per comment: So the actual question is "how do I call a web service?" Take a look a this example. Some more good walkthroughs here.

JP Alioto
  • 44,864
  • 6
  • 88
  • 112
  • Those references don't actually tell you how to rename a file, merely describe the webservice. I formulated this question after reading those documents. – Nat Jun 15 '09 at 01:32