Wednesday, March 15, 2017

Retrieve items from a particular folder of a list

using (SPWeb spWeb = SPContext.Current.Site.AllWebs["Reports"]) { SPList spList = spWeb.Lists.TryGetList("ManageReports"); SPQuery spQuery = new SPQuery(); //Setting the ViewAttribute to "Scope='Recursive'" //fetches all items from the list, //ie., also the items within the folders spQuery.ViewAttributes = "Scope=\"Recursive\""; SPListItemCollection items = spList.GetItems(spQuery); }

Get all the item of specific folder of Document Library or list in SharePoint using C#

string FolderName = "Peak";
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList oList = web.Lists["YourListName"];
                        SPListItemCollection collListItems = null;
                        foreach (SPFolder subFolder in oList.RootFolder.SubFolders)
                        {
                            if (subFolder.Name.ToLower() == FolderName.ToLower().Trim())
                            {
                                SPQuery oQuery = new SPQuery();
                                oQuery.Query = "<OrderBy><FieldRef Name=’Modified’ Ascending=’False’ /></OrderBy>";
                                oQuery.Folder = subFolder;
                                collListItems = oList.GetItems(oQuery);
                                break;
                            }
                        }
                    }

Failed on Start (Workflow was canceled by System Account.)

For your issue, I recommend to follow the steps as below:
  1. Clear SharePoint Designer cache: How to Clear Your SharePoint Designer 2010/2013 Cache
  2. Deactivate all "Workflow" features at the Site Collection level.
  3. Enable all "Workflow" features at the Site Collection level.
  4. PSCONFIG (Not Necessary) (or run the SharePoint 2010 products configuration wizard)
  5. Delete the bad workflow.
  6. Create a new workflow on the list with an valid user.

Workflow 2013 starts and then immediately cancels



1.)    Your user has at least edit permissions on the list
2.)    Your current user has a user profile
a. Navigate to Central Administration -> Application Management -> Select the User Profile Service -> Select manage User Profiles -> Search for your account -> if an account is found you should be fine
3.)    Make sure you are not creating/starting the workflow as the SharePoint Setup/Install account or a System Account
4.)    User Profile Service Application is running
5.)    You are able to complete a full synchronization of the User Profile Service
a. Make sure the User Profile Synchronization Account has replicate directory changes in Active Directory
6.)    Last but not least is an IIS reset
a. An IIS reset will drop existing connections to your web server for a few seconds. It is recommended to do this during non-business hours.

SharePoint 2013 Workflow Cancels Automatically

SharePoint 2013 workflows created with SP Designer would cancel automatically with an internal status of ‘Canceled’ while SharePoint 2010 workflows worked just as expected.


This account needs to have at least contribute permissions to the Workflow History list (a hidden list that can be accessed through SP Designer). So here’s my solution:


  • Navigate to the site that the workflow is on in SharePoint 2013 Designer.
  • Go to All Files -> Lists
  • Right click on Workflow History
  • Select Properties
  • Click on Permissions for this list under the ‘Customization’ section (This should open up the edit permissions page in the browser)
  • Break inheritance on this list by selecting Stop Inheriting Permissions in the new opened browser window
  • Use the check box next to the appropriate group (probably the visitors group) to select the group that needs updated permissions
  • Select Edit User Permissions
  • Grant the group ‘Contribute’ permissions
  • Select OK