Tag Info

Hot answers tagged

6

SharePoint has great built in methods to copy or move documents across sub-sites or lists within the same site collection. You can use SPFile.MoveTo or SPFile.CopyTo. You can even move whole folders and their contents with the SPFolder.MoveTo method. Very nice. Unfortunately, these do not work across site collections. where as use of RootFolder.Files.Add ...


2

Oh man, SPList.Folders actually returns an SPListItemCollection, not an SPFolderCollection... However, SPList.RootFolder.SubFolders does return an SPFolderCollection...


1

You might not have permissiosns to see that file. You should also add a check for file existence like : SPFile u = l.RootFolder.Files.Add(l.RootFolder.Url + "/" + f.Name, f.OpenBinary(), true); if (l.Exists) { l.RootFolder.Update(); l.Update(); w.Update(); }


1

Verify that your $file.Name is truly "myfile.docx". Try these amended lines (with the other lines as is): $DestUrl ="MyDocuments/SubFolderName/" $file.MoveTo($DestUrl + $file.Name, true)


1

ItemUpdating allows you to get the file before the upload/action has taken place. ItemUpdated requires you to go through version history. In code you can get the previous version as follows: SPFile file = ...; SPFileVersion previousVersion = file.Versions[file.Versions.Count - 1];



Only top voted, non community-wiki answers of a minimum length are eligible