2/20/2014

Download a File from SharePoint using PowerShell

 

I recently had a request for a PowerShell script that could be run as a Windows scheduled task to download a file each night to a network share. As is typical, there's more than one way…

 

The PowerShell / .Net approach:

This is a ".Net approach" as it does not use any PowerShell cmdlets (beyond New-Object). The following will work from all versions of PowerShell and SharePoint 2007 – 2013, but not Office 365. It will work from any client PC as long as you have permissions to access the file. Why not Office 365? O365 requires an authentication cookie. (When I get some time I'll post an O365 version.)

$fromfile = "http://yourserver/sites/yoursite/shared%20documents/yourfile.xlsx"
$tofile   = "c:\somedirectory\yourfile.xlsx"

$webclient = New-Object System.Net.WebClient

$webclient.UseDefaultCredentials = $true
#  or
# $webclient.Credentials = …
$webclient.DownloadFile($fromfile, $tofile)

 

The SharePoint Approach:

This approach must be run from a SharePoint server and uses the Get-SPWeb cmdlet to access a site. As it is much more complicated, why would you ever use it? To do more complex things! Things like getting all of the files from a library and then downloading them (in a foreach loop), ZIPing the file(s) before download or otherwise manipulating the files before download.

The following will work from the SharePoint 2010 and 2013 Management Shells (but not for Office 365). Why not Office 365? The following needs to be run on the SharePoint server, and you are not allowed to do that with O365.

$fromsite = "http://yourserver/sites/yoursite"

$fromfile = "yourlibrary/yourfile.xlsx"
$tofile   = "c:\test\yourfile.xlsx"

$web = Get-SPWeb $fromsite
$file = $web.GetFile($fromfile)
$filebytes = $file.OpenBinary()

$filestream = New-Object System.IO.FileStream($tofile, "Create")
$binarywriter = New-Object System.IO.BinaryWriter($filestream)
$binarywriter.write($filebytes)
$binarywriter.Close()

 

.

2/17/2014

SharePoint 2013 and Office 365: Finding GUIDs

 

Years ago I wrote a little article on how to find SharePoint GUIDs for SharePoint 2007. Later I wrote one on how to find the same GUIDs using PowerShell.

Now, here's how to find GUIDs for just about anything using SharePoint 2013's REST web services! The following will work for both on premises and SharePoint Online / Office 365.

---

SharePoint 2013 includes a REST service to access sites, lists and items. In the data that's returned is an ID that is the GUID for the item.

Accessing REST is quite easy as you only need to type it into the address bar of your browser! REST does not work around security, so you will still need to authenticate to your site.

In the examples below "yourdomain" will of course be replaced with your domain name. If using Office 365 it might look like "http://companyname.sharepoint.com.

If you get a result that looks like this…

    image

… you can either use the View Source feature of the browser to see the XML or change the way the browser displays XML. For Internet Explorer:  Tools, Internet Options, Content tab, Feeds and Web Slices Settings and then uncheckmark "Turn on feed reading view",

 

Getting the GUID for your subsite (and a lot more…)

Visit your site, login and then edit your URL to look like this:

https://yourdomain.sharepoint.com/sites/yoursite/yoursubsite/_api/web

Scroll down to the content section and look for the ID element.

image

 

For other objects… sites, lists, items, fields, users…

See the references at the end of this article for even more examples.

The current site collection:
    /_api/Site

Web and Site Features and their GUIDs:
    /_api/web/Features
    /_api/site/Features

 

Lists:
    /_api/web/Lists

A single list (by name):
    /_api/web/Lists/getbytitle('tasks')

A single list (by GUID):
    /_api/web/Lists(guid'c61dc1a2-4982-4dc8-9d78-603d83d81940') (of course using your list's GUID!)

All list items:
    /_api/web/Lists/getbytitle('tasks')/items

A single list item:
    /_api/web/Lists/getbytitle('tasks')/items(12)   (Item with the ID of 12)

List items by criteria:
    /_api/web/Lists/getbytitle('tasks')/items?$filter=Status eq 'Not Started'

 

All list columns, including both display name and internal name!
    /_api/web/Lists/getbytitle('tasks')/Fields

Especially note these two elements:
    <d:InternalName>PercentComplete</d:InternalName>
    <d:Title>% Complete</d:Title>

The current user:
    /_api/web/CurrentUser (No GUID here, but there are other goodies!)

 

There's a lot more that you can do with SharePoint 2013's REST services!

.

1/31/2014

InfoPath 2013 is the last InfoPath!

 

InfoPath 2013 and InfoPath Forms Services in SharePoint 2013 are at the end of life…

See here: http://blogs.office.com/2014/01/31/update-on-infopath-and-sharepoint-forms/

Supported until 2023, but no new versions.

So what will you use for forms?

 

.

1/12/2014

Why use InfoPath?

 

Update 1/31/14: InfoPath 2013 is the last InfoPath!


 

I'm surprised how often people in my SharePoint end user and developer classes don't know what InfoPath is, or if they do, where it can be used in SharePoint. Any discussion of InfoPath leads to a discussion of the future of InfoPath and if it is going away, what the alternatives are. What follows are some of my class notes…

A brief history of InfoPath

  • Formally named XDocs and NetDocs (*)
  • A patented way of authoring XML using DHTML views and XSLT (*)
  • Released in 2003 as part of Microsoft Office Professional 2003
  • Versions: 2003, 2007, 2010, 2013 (matching the releases of Office)
  • Started getting a lot of attention with the release of InfoPath Forms Services with the Enterprise Edition of MOSS 2007

 

InfoPath can be used:

  • To create custom stand alone forms. InfoPath templates can used as library or Content Type templates. When the user submits the form the data can be saved back to a SharePoint library as an XML file or to other destinations such as email or network shares. In SharePoint, saved data is often then processed using workflows to approve the content or to use the data to update other lists or external systems. (The XML format is easy for developers to work with.)
  • To create custom forms for lists. These forms save their data back into a SharePoint list, not as an XML file, but as a list item with the data saved as item properties/columns.
  • To create workflow forms in both SharePoint Designer and Visual Studio workflows. (But SharePoint 2013 workflows only create ASPX forms.)

 

Reasons to use InfoPath:

  • Rich editor to create a form that can look like anything you want.
  • Rules based business logic to hide, show, format and validate fields.
  • External connectivity to offer dropdown lists populated from SharePoint lists, SQL server and many other sources.
  • While a forms designer needs a licensed copy of InfoPath, the end user only needs a web browser. Users do not need any InfoPath product or version if the forms are hosted in the Enterprise Edition of SharePoint 2007, 2010 or 2013.
  • Lots of resources are available: classes, books, blog articles, videos
  • No knowledge of JavaScript, jQuery, XML HTML or CSS needed to create custom forms and custom validation.
  • Multiple views of data. Example: A user might see 50 fields when filling out the form. The approvers might see a 10 field summary and after approval or rejection the user might only see 2 fields and a comments field.
  • Optional bidirectional data (edit a property in the InfoPath form and it updates in the library metadata, edit library metadata and it updates in the InfoPath form - great for workflows!)

 

Reasons not to use InfoPath

  • Yet another tool to learn
  • Unknown future - InfoPath 2013 is largely unchanged from 2010 and SharePoint Designer 2013 workflows only create ASPX forms.
  • There are 3rd party solutions for forms design in SharePoint
  • You must have the Enterprise Edition of SharePoint, otherwise every user must own InfoPath

 

Benefits unique to developers:

  • Much less work to create Initiation, Association and Task forms for Visual Studio workflows
  • Much less work to customize SharePoint Designer workflow forms
  • Everything is XML!
  • No JavaScript, HTML, etc...

 

Disadvantages to developers:

  • We like to write code!
  • There's always something that we want to do that InfoPath can't do but we can do by writing more code.
  • Yet another tool to learn.
  • There's always a better tool somewhere.
  • Need to buy at least one copy of InfoPath.

 

Interesting comments by others…

Andrew Connell says "I do not use InfoPath any more & I do not recommend people use InfoPath going forward." http://www.andrewconnell.com/blog/my-thoughts-infopath-2013-the-future-of-infopath Read all of the comments!

The Office SharePoint blog: "InfoPath is our integrated forms solution for the foreseeable future"
Options to Create Forms in SharePoint 2013 http://blogs.office.com/b/sharepoint/archive/2013/03/04/options-to-create-forms-in-sharepoint-2013.aspx 

MSDN: "In this release, InfoPath 2013 has not introduced new functionality or scenarios."
http://msdn.microsoft.com/en-us/library/office/jj229830.aspx#odc_off15_ta_WhatsNewforO15Developers_InfoPath 

Glen Furnas at sharepoint-community.net: "Simply put, InfoPath is a multi-purpose product that’s been put to use in a wide variety of ways, and no single alternative will ever replace it in all its roles."
http://sharepoint-community.net/profiles/blogs/alternatives-to-infopath-exploring-the-options

Owen Runnals: "In the end I feel custom ASPX pages are the safest bet since they've worked since SharePoint 2007."
http://owenrunnals.blogspot.com/2013/01/the-future-of-custom-forms-in.html

 

Alternatives to InfoPath?

ASPX Forms

maybe Microsoft LightSwitch: http://msdn.microsoft.com/en-us/library/vstudio/jj969620.aspx

Microsoft Access 2013 / Access Apps (but no workflow support)

Nintex Forms: http://www.nintex.com/en-US/Products/Pages/NintexForms.aspx

K2 smartforms: http://www.k2.com/platform/formshttp://www.k2.com/blog/k2-smartforms-vs-microsoft-infopath

.

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.