Follow us on Twitter
Follow us in Facebook
Office Dev Content
SharePoint Dev Content
Blogs for Office developers > Apps for Office and SharePoint blog
Documents are critical pieces of information in many business applications. That’s why we added support for easily attaching to Office 365 or SharePoint document libraries in the latest release of Cloud Business Apps in Visual Studio 2013. With the Microsoft Office Developer Tools for Visual Studio 2013—March 2014 Update, it is now easier than ever to attach to document libraries and interact with documents in your application.
Let’s walk through an example. Imagine we are store owners who sell a variety of products, and would like to use SharePoint to store documents related to those products, such as manuals, warranties, sales presentations, and notes. In this example, we will create a Cloud Business App (CBA) that relates our products to documents stored on Office 365 or SharePoint 2013. We will also create screens to allow access to those related documents.
On the SharePoint site, choose a document library to store documents relating to our products. The document library needs to be on the same site and host web as our CBA app when we deploy, so the app has access to the library. We need to create a column to track which product the document belongs to, in this case use the string field Product. While the document library list can have associated content types, the shared column needs to be a list column so it is available for every document.
Note: If we had created the Cloud Business App with a previous version of Visual Studio, upgrade the app and update the SharePoint data sources. If the entities were SharePoint Document Libraries they will be ready for use after the update. To upgrade the app, choose the project in Solution Explorer and select "Upgrade Project..."
a. Add a new field ProductName as type string.
Set the Include in Unique Index property for this field so we do not have two products with the same name. Alternatively, we can choose to auto-populate a string field with any unique key, like a GUID, by writing code in the Product_Inserting event. We need a unique field so it can be associated with a column on the document library.
Choose Start Debugging (F5) to start the app. We may need to enter our credentials and we will need to trust the app. When the app loads, it will open to the Product page where we can add a product.
Once the product is added, select the product to view details and open the Product Documents tab. Choose the Add button to create a new document or upload an existing document. The item named Document is the default template added for new document libraries. We can customize which templates are associated with the library in SharePoint and they will appear in the popup list for easy creation. For now, create a Word document.
This will open the document in Office Online. Using Office Online, we can rename the document by selecting the name on the menu bar and add our content to the document body.
When the edits are complete, just choose the back button to return to the product view page. Office Online auto-saves your document—so we don't need to explicitly save.
Selecting the document in the tile list will open the document to allow viewing or editing. It will open the desktop Office client if we have it installed or Office Online if the desktop version is not installed.
CBA apps have flexible deployment options. When we run the Publish Wizard, the SharePoint library address will automatically be updated to point at the host web of the publish site. Create the library with the same columns on this site so the app can find it.
Once the app is published, we can access the app on desktop, tablet, or phone and the layout will adjust for the best experience. Here's what it looks like on my phone. Pretty cool!
To allow uploading documents on legacy browsers such as Internet Explorer 9, add a NuGet package to the server project. Choose the server project and choose Manage NuGet Packages from the context menu. In the NuGet manager, select Online, search for "web pages," choose Microsoft ASP.NET Web Pages package, and select Install. This package will also install two dependent packages; Accept the license agreement to install the packages.
The Troubleshooting document libraries topic provides more information about enabling legacy browser support.
The document library support added in the Office Developer Tools for Visual Studio—March 2014 Update provides a way to seamlessly integrate SharePoint document libraries into your applications, without needing to write any code. CBA apps excel at showing a table entity and all of its related documents. Uploading documents, creating new documents from templates or blank Word, Excel, or PowerPoint documents, and editing documents in Office Online or Office desktop are supported.
The How Do I: Incorporate Document Libraries in a Cloud Business App? topic provides a video demonstration about integrating document libraries.
-Ed Smith, Software Development Engineer in Test, Cloud Business Applications Team