Skip to content

Instantly share code, notes, and snippets.

View garima2510's full-sized avatar

Garima Agrawal garima2510

View GitHub Profile
@garima2510
garima2510 / App.css
Last active January 6, 2017 14:49
Demo of Knockout.js with Sharepoint 2013
.tableStyle {
border-collapse:collapse;
border: 1px solid black;
text-align:center;
width:50%;
padding:15px;
}
@garima2510
garima2510 / App.css
Last active December 28, 2015 18:09
Demo of Knockout.js with Sharepoint 2013 - Adding Items
.tableStyle {
border-collapse:collapse;
border: 1px solid black;
text-align:center;
width:50%;
padding:15px;
}
.messages {
display:none;
@garima2510
garima2510 / App.css
Last active December 28, 2015 20:39
Demo of Knockout.js with SharePoint 2013 - Removing Items
/* Place custom styles below */
.tableStyle {
border-collapse:collapse;
border: 1px solid black;
text-align:center;
width:50%;
padding:15px;
}
@garima2510
garima2510 / uploadfile.cs
Last active August 29, 2015 14:03
O365 - CSOM upload 2MB files
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext, SPHostUrl);
using (var clientContext = spContext.CreateUserClientContextForSPAppWeb())
{
if (clientContext != null)
{
//code for file size < 2MB
//file is the input which we uploaded. It can be taken from Request.Files
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = System.IO.File.ReadAllBytes(file.FileName);
@garima2510
garima2510 / uploadfilelarge.cs
Created June 30, 2014 05:24
O365 - CSOM upload large files
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext, SPHostUrl);
using (var clientContext = spContext.CreateUserClientContextForSPAppWeb())
{
if (clientContext != null)
{
//file is uploaded file. Could be read from Request.Files
using (FileStream fs = new FileStream(file.FileName, FileMode.Open))
{
//code for file size > 2MB. tested upto 50MB
@garima2510
garima2510 / uploadfilestream.cs
Last active August 29, 2015 14:07
O365 - Upload Large File Without File Stream
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext, SPHostUrl);
using (var clientContext = spContext.CreateUserClientContextForSPAppWeb())
{
if (clientContext != null)
{
FileCreationInformation newFile = new FileCreationInformation();
//here file is the selected file. In this case of type HttpPostedFileBase
newFile.ContentStream = file.InputStream;
@garima2510
garima2510 / GetMySiteUrl.cs
Last active August 29, 2015 14:07
Get My Site Url
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.UserProfiles;
using (ClientContext clientContext = new ClientContext("https://tenant.sharepoint.com/"))
{
SecureString passWord = new SecureString();
foreach (char c in "your_password".ToCharArray()) passWord.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials("your_email_id", passWord);
@garima2510
garima2510 / checkmysite.cs
Last active August 29, 2015 14:07
Check If My Site Exists
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.UserProfiles;
using (ClientContext clientContext = new ClientContext("https://tenant.sharepoint.com/"))
{
SecureString passWord = new SecureString();
foreach (char c in "your_password".ToCharArray()) passWord.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials("your_email_id", passWord);
@garima2510
garima2510 / CopyDocument.cs
Created October 31, 2014 11:16
ProviderHostedApp - CopyDocument
string filePath = "/TestLibrary/TestDocument.pptx";
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
using (var sourceContext = spContext.CreateUserClientContextForSPHost())
{
Microsoft.SharePoint.Client.File sourceFile = sourceContext.Web.GetFileByServerRelativeUrl(filePath);
//file stream will be used to upload in destination library
var fileStream = sourceFile.OpenBinaryStream();
sourceContext.Load(sourceFile, k => k.ServerRelativeUrl, k => k.Name);
sourceContext.ExecuteQuery();
public class HomeController : Controller
{
private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"]; //clientId
private static string appKey = ConfigurationManager.AppSettings["ida:AppKey"]; //clientSecret
private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"]; //https://login.windows.net/{0}
private static string tenant = ConfigurationManager.AppSettings["ida:Tenant"]; //TenantName.onmicrosoft.com
private const string ResourceUri = "https://onenote.com";
public static readonly string Authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);//https://login.windows.net/TenantName.onmicrosoft.com
Uri returnUri = new Uri("https://localhost:44327/Home/ReturnFlow");