Skip to content

Commit

Permalink
Changed documentation to MD format
Browse files Browse the repository at this point in the history
  • Loading branch information
jansenbe committed Aug 19, 2014
1 parent 9f01815 commit 053adc3
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 21 deletions.
5 changes: 2 additions & 3 deletions Scenarios/Core.FileUpload/Core.FileUpload.sln
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30501.0
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.FileUpload", "Core.FileUpload\Core.FileUpload.csproj", "{CD37F794-DFE0-40E5-8AB5-7439215E5F19}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.FileUploadWeb", "Core.FileUploadWeb\Core.FileUploadWeb.csproj", "{88144026-27DD-4FBA-ADEF-91261A8DD2FA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documentation", "Documentation", "{2F7D2E6E-1116-4CEC-8CC2-E10194D085D5}"
ProjectSection(SolutionItems) = preProject
File Upload.docx = File Upload.docx
Readme.txt = Readme.txt
readme.md = readme.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{30BAB15D-A8B9-443A-9F54-7ED46E0C0312}"
Expand Down
Binary file removed Scenarios/Core.FileUpload/File Upload.docx
Binary file not shown.
18 changes: 0 additions & 18 deletions Scenarios/Core.FileUpload/Readme.txt

This file was deleted.

91 changes: 91 additions & 0 deletions Scenarios/Core.FileUpload/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# File Upload CSOM SharePoint App #

### Summary ###
This simple sample shows how to upload a large file into a SharePoint Library and Folder using client side object model from within a SharePoint App.

### Applies to ###
- Office 365 Multi Tenant (MT)
- Office 365 Dedicated (D)
- SharePoint 2013 on-premises

#### Note: ####
Requires small adjustments for Office 365 Dedicated (D) and SharePoint 2013 on-premises

### Prerequisites ###
None

### Solution ###
Solution | Author(s)
---------|----------
Core.FileUpload | Vesa Juvonen (**Microsoft**)

### Version history ###
Version | Date | Comments
---------| -----| --------
1.0 | May 8th 2014 | Initial release

### Disclaimer ###
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**


----------

# General comments #
This scenario shows uploading files to SharePoint using client side object model. The first scenario will upload a document to a library, the second scenario will upload a document to a folder within the library. This sample solution uses an extension method UploadDocumentToLibrary & UploadDocumentToFolder defined in the FileFolderExtensions in the OfficeDevPnP Core project.

# SCENARIO: UPLOAD A FILE TO LIBRARY USING CSOM #
This scenario shows how to upload a file larger than 2MB to a SharePoint library using CSOM from a SharePoint application. We will upload a document host web to new library called Docs, which will be created if it doesn’t exist.

```C#
ctx.Web.UploadDocumentToLibrary(HostingEnvironment.MapPath(string.Format("~/{0}", "Resources/SP2013_LargeFile.pptx")), "Docs", true);
```

The below code shows the implementations code of the solution

```C#
using (FileStream fs = new FileStream(filePath, FileMode.Open))
{
FileCreationInformation flciNewFile = new FileCreationInformation();
// This is the key difference for the first case - using ContentStream property
flciNewFile.ContentStream = fs;
flciNewFile.Url = System.IO.Path.GetFileName(filePath);
flciNewFile.Overwrite = true;

Microsoft.SharePoint.Client.File uploadFile = list.RootFolder.Files.Add(flciNewFile);

list.Context.Load(uploadFile);
list.Context.ExecuteQuery();
}
```

# SCENARIO: UPLOAD A FILE TO FOLDER USING CSOM #
This scenario shows how to upload a file larger than 2MB to a folder in a SharePoint library using CSOM from a SharePoint application. We will upload a document to a host web to a hidden folder called “hiddentest”. We will create the folder if it doesn’t already exist. Since the folder is not visible from the browser UI, you may navigate to the folder using the URL in your browser.

```C#
ctx.Web.UploadDocumentToFolder(HostingEnvironment.MapPath(string.Format("~/{0}", "Resources/SP2013_LargeFile.pptx")), "hiddentest", true);
```

The below code shows the implementations code of the solution

```C#
if (!folder.IsObjectPropertyInstantiated("ServerRelativeUrl"))
{
web.Context.Load(folder);
web.Context.ExecuteQuery();
}

using (FileStream fs = new FileStream(filePath, FileMode.Open))
{
FileCreationInformation flciNewFile = new FileCreationInformation();

// This is the key difference for the first case - using ContentStream property
flciNewFile.ContentStream = fs;
flciNewFile.Url = System.IO.Path.GetFileName(filePath);
flciNewFile.Overwrite = true;

Microsoft.SharePoint.Client.File uploadFile = folder.Files.Add(flciNewFile);

folder.Context.Load(uploadFile);
folder.Context.ExecuteQuery();
}
```

0 comments on commit 053adc3

Please sign in to comment.