Domanda

Currently I'm looping through all the files in a collection, which is every single document in the library. Once I find the unique document name, I move it.

I'm trying to getting away from looping over thousands of records.

Maybe i can write a CAML query that will reduce the files in the collection maybe?

    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;
      }
    }
È stato utile?

Soluzione

I figured it out.

You can use SPFile to check if the file exist in the library and then move it if it does.

SPFile file = site.GetFile("/Final Candidates/" + CName);

if (file.Exists)
{
   file.MoveTo("Draft Candidates/" + CName, true);
}

Reference: https://stackoverflow.com/questions/359672/how-to-determine-if-a-file-exists-in-a-sharepoint-spfolder

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top