戰地連結︰ Home My Flickr NBA.com About

2008年5月11日星期日

Copying Files between Document Libraries in WSS 3.0 Workflow

Overview

Sometimes you would need to move/copy files to different Document Libraries during a workflow process, but when using 'File.CopyTo' or 'File.MoveTo' method there may be build errors. If this is the case, then you can use the following snippet (Copied from 'cwogle' ) to manually 'copy' a file to the destination Document Library.

On the other hand, if you want to copy the whole SPListItem to another Document Library, then you can use 'SPListItem.CopyTo()' method.

Reference

moving sharepoint files to different folder

Code Snippet

    1 // Get Destination Folder

    2 SPWeb currWeb = workflowProperties.Web;

    3 SPFolder destnFolder = currWeb.GetFolder("http://host/DocLibrary/");

    4 

    5 // Copy the File to there

    6 SPListItem item = workflowProperties.Item;

    7 Byte[] fileContents = item.File.OpenBinary();

    8 SPFile newFile = destnFolder.Files.Add(

    9     destnFolder.ServerRelativeUrl + "/" + item.File.Name,

   10     fileContents,

   11     item.File.Author,

   12     item.File.ModifiedBy,

   13     item.File.TimeCreated,

   14     item.File.TimeLastModified);

沒有留言: