News

Rebecca Isserman's Facebook profile

My Stats

  • Posts - 104
  • Comments - 121
  • Trackbacks - 0

Twitter












Tag Cloud


Recent Comments


Recent Posts


Archives


Post Categories


Blogs on SharePoint


Other Blogs


Resources on Sharepoint


Stuff



As you all know I write a lot of maintenance console applications to perform upgrades on huge subsets of sites.  This week I was asked to create a console application that will cut down six documents libraries into three document libraries.  I wanted to use the CopyTo() Function, but there is a bug.  I did find a nice MoveTo() Function in SPFile.  I ended up using that code instead here is a little sample:

 //copy documents and deletes libraries
            SPList ProposalsWord = Web.Lists["Proposal Template (Word)"];
            foreach (SPListItem Item in ProposalsWord.Items)
            {
                SPFile File = Web.GetFile(Item.Url);
                try
                {
                    File.MoveTo(Web.Url + "/Sample%20Proposals%20PDF/" + Item["Name"].ToString());
                }
                catch (Exception)
                {
                }
            }
            ProposalsWord.Delete();

This piece of code loops through the items on one document library and moves them to another document library.  It is fairly simple and straight forward.  If you have any comments or questions please let me know.


posted @ Friday, May 30, 2008 8:57 AM | Filed Under [ MOSS ]

Comments

Gravatar # re: Moving Documents from One Document Library to Another
Posted by Nicole on 7/10/2008 8:56 AM
Does this move all the metadata associated with the document too? I am trying to move documents that are attached to a content type to another library that has that content type as well....
Gravatar # re: Moving Documents from One Document Library to Another
Posted by MOSSLover on 7/10/2008 10:38 AM
The metadata is only moved for Office Documents. It also will not move Modified, Modified By, Created, Created By. So if you are using another document type and a different field type, then you can add the metadata after it is moved.
Gravatar # re: Moving Documents from One Document Library to Another
Posted by Bonney on 7/21/2008 1:48 AM
The given code gives the following exception :
The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.

Please help me out!!

Gravatar # re: Moving Documents from One Document Library to Another
Posted by MOSSLover on 7/22/2008 11:14 AM
What kind of access do you have for the library? Are you running the whole code, delete and move documents?
Gravatar # re: Moving Documents from One Document Library to Another
Posted by Bonney on 7/29/2008 5:35 AM
I have over come the error :)
I had to select the 'On' option of the web application from web application general settings.

Thanx anyway.
Post a comment





 

Please add 2 and 2 and type the answer here: