Abe Miessler
Abe Miessler

Reputation: 85056

How to move files with metadata in SharePoint?

I have written some code that copies files and their metadata to a new URL. But for some reason it's only copying metadata for Word and Excel files. Anything non-microsoft, like PDFs do not get their metadata copied. My code is below, does anyone see anything I should change?

Also, this code worked for PDFs when it ran under 2007...

static void CopyFileWithHistoryCrossSite(SPFile sourceFile, SPFolder destination, string destinationUrl)
{
    byte[] binFile;

    binFile = sourceFile.OpenBinary();

    destination.Files.Add(destinationUrl, binFile, true);
}

Upvotes: 2

Views: 6484

Answers (2)

Jeroen Ritmeijer
Jeroen Ritmeijer

Reputation: 2792

Have a look at this discussion on SO: When is SPFile.Properties != to SPFile.Item.Properties in SharePoint?

Upvotes: 1

Alexei Levenkov
Alexei Levenkov

Reputation: 100547

This code will not "copy metadata" in destination, the metadata will be recreated based on the stream of the file's stream (it is called "property promotion", see http://msdn.microsoft.com/en-us/library/aa979617.aspx).

Try SPFile.CopyTo/MoveTo as I think they may copy metadata.

Upvotes: 3

Related Questions