Wednesday, January 16, 2013

How to move custom List Item to a folder within the list




  •  $item = $List.GetItemById(1)
  • $file = $web.GetFile($item.Url)
  • $file.MoveTo($item.ParentList.RootFolder.Url + "/Folder/" + $item.ID +"_.000")

Here is my script sequence. 

PS N:\> $item = $List.GetItemById(5)
PS N:\> $item.ResetRoleInheritance()
PS N:\> $file = $web.GetFile($item.Url)
PS N:\> $file.MoveTo($item.ParentList.RootFolder.Url + "/XXFOLDER/" + $item.ID +"_.000")
PS N:\> $item = $List.GetItemById(6)
PS N:\> $item.ResetRoleInheritance()
PS N:\> $file = $web.GetFile($item.Url)
PS N:\> $file.MoveTo($item.ParentList.RootFolder.Url + "/XXFOLDER/" + $item.ID +"_.000")
PS N:\>

Monday, January 14, 2013

Workflow not running when item updated from event receiver.



I finally found the post to solve my problem of having to run workflow from SPItem.Update()

"

workflow's and event handlers run on a different thread than the main thread. You just cannot create another Console/Windows Application and have it trigger the workflow and just quit.
Quitting the application before the asyc worker threads finish their work, causes those threads to simply abort. In case of workflow, it would seem as workflow never fired !!
So what is the fix here? Use the following line of code
SPSite.WorkflowManager.Dispose();

after updating the item. So effectively the overall code becomes:
using(SPSite site = new SPSite(url))
{
    using(SPWeb web = site.OpenWeb())
    {
        SPList list = web.GetList(url);

        SPListItem item = list.Items[1];
        item[updateField] = DateTime.Now.ToLongDateString();
        item.Update();
        site.WorkflowManager.Dispose();
    }
}
Now when I ran the console application, as expected the item updates and the workflow is triggered 

"
Source: http://blogs.msdn.com/b/malag/archive/2008/07/11/splistitem-update-not-starting-workflow.aspx

Thursday, January 10, 2013

How to move list items between SharePoint lists

One of the ways for simple list items is as follows. 

  • Go the folloing link
    • (http://<Sharepoint Sites>/_Layouts/sitemanager.aspx) 
  • Select the items you wish to copy
  • Select the Destination list
  • Done. 

Tuesday, January 8, 2013

Workflow to move a document to a folder within the same Document Library/List

  • Create Workflow 
  • Update the current Item 
  • Set Path and Name field to desired [folder Name]/Current Item Name
  • Save
  • Publish
  • Done