0

I'm probably not doing the move the most efficient way for starters, because I'm only moving one file...not a group of files. I'd rather not have to loop through the library to find the file i want to move.

SPFileCollection collFiles = site.GetFolder("Final Candidates").Files;
for (int intIndex = collFiles.Count - 1; intIndex > -1; intIndex--)
{
  if (collFiles[intIndex].Name == CName)
  {
    collFiles[intIndex].MoveTo("Draft Candidates/" + CName, true);
    break;
  }
}

Once I move the file to the other library, I need to update some columns by querying the ID. How do you get the new ID of a file that is moved?

  • I don't want to query the file by name because of the ominous query limit...and Microsoft in their infinite wisdom chose not to index that column. – jpollar Jan 8 '16 at 16:07
  • MoveTo is a void returning method so it isn't going to give you the new ID so you'll have to find it. It should not change the GUID, so you could try to query for the moved item by it's GUID in the new library or just try getting a reference by GUID in the new library? – Eric Alexander Jan 8 '16 at 18:39
  • That's what I thought...thanks Eric. Any suggestions on improving the MoveTo? I hate having to loop through every damn document to find the one i want to move. Every official source says to do it this shitty way. – jpollar Jan 8 '16 at 19:42
-1

What you can try is to get the highest item id in the "another library" before moving the files. Then you would be able to determine the new item ID depending on the position of the loop counter. You can order by the ID, descending, with a rowlimit of 1 in your CAML query to get the highest ID

  • That's not going to be fool proof...this is a textbook example of what they tell you NOT to do. – jpollar Jan 8 '16 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.