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;
bi开发者_Python百科nFile = sourceFile.OpenBinary();
destination.Files.Add(destinationUrl, binFile, true);
}
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.
Have a look at this discussion on SO: When is SPFile.Properties != to SPFile.Item.Properties in SharePoint?
精彩评论