Upload a file to SharePoint by PowerShell

Question from a friend

A friend of a friend asks:

I know there’s stuff all over the web that tells developers how to programmatically store documents into a SharePoint 2013 document library, but what source would you recommend? One of the groups on one of my projects has an image capture application built in Visual Basic. They need to be able to create folders within a SharePoint 2013 document library and store reports in that folder.

And my friend adds:

Would this just be powershell?

I know folders are stored as items like a file is. Do you have any good pointers to technet docs or other material?

A higher level question, is the folder concept a good idea in content management system? I would think individual file permission would be a cleaner method

PowerShell File Upload

First things first – if you want to upload a file to SharePoint using PowerShell, there are plenty of examples on the web that can help. I tested the code from a wiki entry on TechNet, SharePoint 2010: Upload File in Document Library Using PowerShell, and it worked great.

PowershellUpload

Other Options

PowerShell isn’t the only option, since the original asker mentions programming, I have a feeling PowerShell might not be their go to tool, yet. PowerShell is super powerful and allows access to the full SharePoint API, but it is a newer tool and there are still plenty of reasons to choose other development tools like Visual Studio.

I haven’t tested the code in How to programmatically upload a document in a SPDocumentLibrary, but it’s just one example of the resources available for the Server Side SharePoint API and it looks like it would work to me. In SharePoint 2013, the Microsoft Documentation refers to this type of programming as a Farm Solution, check out Build farm solutions in SharePoint 2013 for more information on how to get started in 2013 or Getting Started with SharePoint Development for SharePoint 2007.

The newest development in SharePoint programming is the Client Side Object Model. For SharePoint 2013 especially, this is a great option. Check out Working with folders and files with REST for examples of uploading files and creating folders. The advantage of this model is that it doesn’t require any special development environment setup or assume ASP.Net knowledge. REST is a model that can be used by Java or PHP developers just as easily as .Net Developers.

Use Metadata

My friend latched onto an important concept to grasp in SharePoint. On file shares, we only have one way to group our files – folders. In SharePoint, we have so many options! For example, if I wanted to group my files by date on a file share, I normally would create a folder for every year, then one for each month under the year, and maybe the week under that. In SharePoint, I can group by date with a simple change to the view!

GroupedByCreatedDate

Take a look at some of the answers to my question on twitter, If you had to choose between creating a folder or using metadata for a SharePoint Document Library, which would you choose?:

Metadata – more flexible and less confusing for user! – https://twitter.com/OWirkus

really Tom? It’s 9am on New Year’s Day. Also the answer is obviously metadata if you have the option. 🙂 – https://twitter.com/justinong1

depends on the situation. I’d almost always go for metadata, but some permissions/retention scenarios call for folders-sadly –  https://twitter.com/TashasEv

presentation: http://www.jasperoosterveld.com/2013/12/office-365-saturday-europe-2013-my.html blogpost: http://www.jasperoosterveld.com/2013/11/from-file-shares-to-document-libraries.html webinar recording: http://www.jasperoosterveld.com/2013/09/recording-webinar-from-file-shares-to.html – https://twitter.com/SharePTJasper

Take Advantage of SharePoint Books

For those new to working with SharePoint, it can be hard to filter all of the content available and find the best resources. In general, I recommend checking out some of the awesome books published on SharePoint, as those sources have been reviewed for accuracy. If you’re new, read a book, there is a lot to learn and that is a cheap and easy way to start.

Amazon has an entire Department for SharePoint Books

DepartmentForSharePointBooks

One thing I love about Amazon is that you have all kinds of sorting and filtering options and you can read reviews from other readers to make sure you find the right book.

I also recommend http://www.safaribooksonline.com/ for digital books on technology. I use it often. My favorite features are the iOS App for Offline Reading and the ability to search through all of their books.

Asking Questions

When you have a question I can’t answer easily from TechNet, MSDN or books, I have three places I normally go:

  1. Twitter, use hashtag #sphelp to connect to others to answer short questions, for example https://twitter.com/resing/status/418392124963307520TwitterSPHelp
  2. MSDN/TechNet Forums, for example How to upload files to SharePoint using c#
  3. SharePoint.StackExchange.com, for example Where are uploaded files stored?

Reference

1 Comment

    Leave a Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.