SharePoint Nirvana | Sharepoint

Deleting SharePoint Items remotely via Powershell

by JamieMcAllister 16. December 2016 03:27
Recently I was trying to put together a really quick solution to delete some SharePoint 2010 items remotely using Powershell script. It'd be quite usual to incorporate CSOM into such a solution, but as I had some legacy powershell performing actions via the SharePoint web services (lists.asmx) it seemed like I could hack it together quicker that way. How wrong I was! To cut a long story short it turned out that the MSDN documentation on this is wrong! This led to head scratching and a much slower resolution than I was after. The MSDN documentation is here; Some wrong MSDN Docco This tells you that to delete multiple list items you need to build a package for the web service call like this; <Batch OnError="Continue" ListVersion="1" ViewName="270C0508-A54F-4387-8AD0-49686D685EB2"> <Method ID="1" Cmd="Delete"> <Field Name='ID'>2</Field> </Method> <Method ID="2" Cmd="Delete"> <Field Name='ID'>8</Field> </Method> </Batch> See how it just requires the ID values? WRONG! It turns out it needs the FileRef attribute too otherwise you're in a world of pain; <Batch OnError="Continue" ListVersion="1" ViewName="270C0508-A54F-4387-8AD0-49686D685EB2"> <Method ID="1" Cmd="Delete"> <Field Name='ID'>2</Field><Field Name="fileRef">http://domain/sites/TheSite/TheLibrary/The File 223.pdf</Field> </Method> <Method ID="2" Cmd="Delete"> <Field Name='ID'>8</Field><Field Name="fileRef">http://domain/sites/TheSite/TheLibrary/The File 991.pdf</Field> </Method> </Batch>   So assuming you've put the above XML together in your powershell, how do you invoke the delete via web services? Like this; $batchElement = [The XML from above] $SiteName = "http://MyDomain/sites/TheSite" $listName = "TheLibrary" $ServiceDesc = $SiteName + "/_vti_bin/lists.asmx?WSDL" $service = New-WebServiceProxy -UseDefaultCredential -uri $ServiceDesc $results = $service.UpdateListItems($listName, $batchElement) You can then check your $results XML for success codes (or other!) Happy SharePointing!


CSOM | Powershell | Sharepoint | sharepoint 2010

My SharePoint Online Sessions Now Available at Channel9

by JamieMcAllister 18. November 2014 14:19
I recently had the chance to do some SharePoint online education sessions on camera, a first for me. Here are the links, see how it went! [More]


Cloud | Document Management | End User | Im Speaking At | MVA | MVP | Office 365 | Public Speaking | Sharepoint | SharePoint Online | video | WCM | Webinar

Create Multiple Document Sets with Powershell

by JamieMcAllister 9. April 2014 09:47
A quick example of how to create multiple Document Sets in SharePoint driven by a CSV file for the names and properties. Changing a couple of lines would allow this script to create simple Folders instead (but Document Sets are better!). [More]

Tags: , , ,

Powershell | Sharepoint | sharepoint 2010 | SharePoint 2013

How to Write SharePoint Code for Bad Performance

by JamieMcAllister 31. January 2014 08:53
Whilst browsing some SharePoint blogs I came across an interesting code sample. The code showed how to edit item properties in an Event Receiver on a library.Here's a partial excerpt; using (SPSite site = new SPSite(properties.Web.Site.ID)) {     using (SPWeb web = site.OpenWeb(properties.Web.ID))     {         SPList list = web.Lists[properties.List.ID];           SPListItem item = list.Items.GetItemById(properties.ListItemId);    This code caught my eye, because it was totally unnecessary to instantiate the SPSite and SPWeb objects to get a handle to the list item. Far better to just use event properties without instantiating anything! properties.ListItem  So, in for a penny, in for a pound I thought I'd compare the code performance. In a standalone dev environment with a few list items the bad code would run fine. I have access to a test environment with tens of thousands of items, which provided a better test of Production-like conditions. The good code executed in 30ms fairly consistently, according to the logs. Fair enough.  What I found was the bad code execution time started climbing as I fired more and more items into the list and triggered the event receiver more often. I gave up when the bad code was executing in 12000 milliseconds. Yup. In my sizable library, the bad code ran 400 times slower than the code using properties.ListItem!! This is why it's not good practice instantiating unnecessary SPSite and SPWeb objects. (So also consider SPContext.Current when you're not in Event Receivers for similar reasons). Also shows you why you shouldn't trust code samples on blogs without a bit of code review (including mine!). Happy SharePointing!


.NET | Development | Event Receiver | Sharepoint | sharepoint 2010 | SharePoint 2013

Hiding Multiple Ribbon Buttons

by JamieMcAllister 10. January 2014 10:38
For a particular Form Library I was interested in making it difficult to do too much with the Forms except add them. I employed a range of measures, one of which was to hide the ribbon buttons for Sharing or opening with Explorer View.  This can be done by creating a customAction and deploying it to your site. Some of this is documented elsewhere, but I noticed that there were no examples showing multiple buttons hiding - the examples showed a single instance. Also the examples always showed a "RegistrationId" of 101, without explaining that this targeted Document Libraries. To target Form Libraries I had to dig up the fact that "RegistrationId" of Form Libraries is 115. The xml looks like this; <?xmlversion="1.0"encoding="utf-8"?> <Elementsxmlns="">   <CustomAction     Id="RemoveRibbonButton"     Location="CommandUI.Ribbon"     RegistrationId="115"     RegistrationType="List">     <CommandUIExtension>       <CommandUIDefinitions>         <CommandUIDefinitionLocation="Ribbon.Library.Actions.OpenWithExplorer" />         <CommandUIDefinitionLocation="Ribbon.Library.Actions.ExportToSpreadsheet" />         <CommandUIDefinitionLocation="Ribbon.Library.Actions.OpenWithAccess" />         <CommandUIDefinitionLocation="Ribbon.Library.Share.ViewRSSFeed" />         <CommandUIDefinitionLocation="Ribbon.Library.Share.AlertMe" />         <CommandUIDefinitionLocation="Ribbon.Library.Share.EmailLibraryLink" />         <CommandUIDefinitionLocation="Ribbon.Library.Actions.TakeOfflineToClient" />         <CommandUIDefinitionLocation="Ribbon.Library.Actions.ConnectToClient" />       </CommandUIDefinitions>     </CommandUIExtension>   </CustomAction>   </Elements>   To get this into your site, create an empty SharePoint project in Visual Studio. A sandboxed solution is fine. Add a feature to the project, and paste the above XML into the Elements.xml file. Smallest scope for the feature is Web. Build and add the WSP to your Solution Gallery via Site Collection Settings. When activated, and the Feature activated in a given Web, it will hide the named buttons in all Form Libraries in the current SPWeb. Here's a list of other elements you could hide using the above method; Mike Smith kindly documented the many Registration IDs for different libraries here; Happy SharePointing!

Tags: ,

Sharepoint | sharepoint 2010

What's The Point Of SharePoint?

by JamieMcAllister 6. February 2013 00:02
When I'm teaching End Users about SharePoint, they often ask what SharePoint has to offer above when they collaborate using email and file shares. This is what I tell them. [More]

Tags: , ,

Document Management | Search | Sharepoint | sharepoint 2010 | SharePoint 2013 | File Share

SharePoint Projects and Technical Debt

by JamieMcAllister 25. January 2013 20:08
I've been nursing a pet theory that SharePoint projects are particularly prone to incurring Technical Debt. If true this is bad for scaleability and maintenance of a type of solution that we'd like to scale well and be easy to change. What are we to do about it? [More]

Tags: , ,

Development | Sharepoint | sharepoint 2010 | SharePoint 2013 | Technical Debt

Jamie McAllister is Speaking at SharePoint Evolution Conference 2013

by JamieMcAllister 8. January 2013 12:05
I will be speaking at SharePoint Evolution Conference 2013 in London next April. This is going to be a great opportunity to meet face to face many of the most influential SharePoint professionals. [More]


Im Speaking At | MVP | Public Speaking | Sharepoint | sharepoint 2010 | SharePoint 2013

SharePoint Video Views Going Well

by JamieMcAllister 8. January 2013 00:41
The SharePoint tutorial videos I posted to YouTube seem to be getting a lot of views. Here is a link. [More]


Sharepoint | sharepoint 2010 | video

SharePoint MVP for 2013

by JamieMcAllister 1. January 2013 21:02
Today I became SharePoint MVP for 2013. Great start to the year! [More]

Tags: , ,

MVP | Sharepoint

Disclaimer: The software, source code and guidance on this website is provided "AS IS"
with no warranties of any kind. The entire risk arising out of the use or
performance of the software and source code is with you.

Any views expressed in this blog are those of the individual and may not necessarily reflect the views of any organization the individual may be affiliated with.