Skip to content

Instantly share code, notes, and snippets.

View chakkaradeep's full-sized avatar
🎯
Focusing

Chakkaradeep Chandran chakkaradeep

🎯
Focusing
View GitHub Profile
@chakkaradeep
chakkaradeep / Create Contact
Created August 11, 2014 06:06
Office 365 API Contacts - Create Contact (along with a contact picture)
public static async Task Create(MyContact myContact)
{
//create the Exchange contact
IContact contact = new Contact();
contact.GivenName = myContact.Name;
contact.DisplayName = myContact.Name;
contact.EmailAddress1 = myContact.Email;
contact.JobTitle = myContact.JobTitle;
//add the contact
@chakkaradeep
chakkaradeep / Get Contacts
Created August 11, 2014 06:08
Office 365 API Contacts - Read Contacts
public static async Task<ObservableCollection<MyContact>> GetContacts()
{
ObservableCollection<MyContact> myContactList = new ObservableCollection<MyContact>();
//query contacts
var contactsResults = await _exchangeClient.Me.Contacts.OrderBy(c=>c.DisplayName).ExecuteAsync();
//fetches the first 50 contacts
//default page count is 50
var contacts = contactsResults.CurrentPage.ToList();
@chakkaradeep
chakkaradeep / Get Contact Picture
Created August 11, 2014 06:09
Office 365 API Contacts - Get Contact Picture
public static async Task<byte[]> GetContactImage(string strContactId)
{
byte[] bytesContactPhoto = new byte[0];
//query the contact by contact Id
//GetById is broken so you need to use this instead
var contact = await _exchangeClient.Me.Contacts[strContactId].ExecuteAsync();
if (contact != null)
{
@chakkaradeep
chakkaradeep / Update Contact
Created August 11, 2014 06:11
Office 365 API Contacts - Update Contact
public static async Task<bool> Update(MyContact myContact)
{
bool bStatus = false;
//myContact is my business object
//query the contact by contact Id
//GetById is broken so you need to use this instead
var contact = await _exchangeClient.Me.Contacts[myContact.Id].ExecuteAsync();
if (contact != null)
@chakkaradeep
chakkaradeep / Delete Contact
Created August 11, 2014 06:11
Office 365 API Contacts - Delete Contact
public static async Task<bool> Delete(string strContactId)
{
bool bStatus = false;
//query the contact by contact Id
//GetById is broken so you need to use this instead
var contact = await _exchangeClient.Me.Contacts[strContactId].ExecuteAsync();
if (contact != null)
{
@chakkaradeep
chakkaradeep / Get All Files
Created August 12, 2014 06:03
Office 365 API My Files - Get All Files
public static async Task<ObservableCollection<MyFile>> GetMyFiles()
{
ObservableCollection<MyFile> myFilesList = new ObservableCollection<MyFile>();
var filesResults = await _spFilesClient.Files.ExecuteAsync();
var files = filesResults.CurrentPage.OfType<Microsoft.Office365.SharePoint.File>().ToList();
foreach (var file in files)
{
@chakkaradeep
chakkaradeep / Get All Files from a Folder
Last active August 29, 2015 14:05
Office 365 API My Files - Get All Files from a Folder
public static async Task<ObservableCollection<MyFile>> GetMyFiles(string strFolderName)
{
//MyFile is the business object
ObservableCollection<MyFile> myFilesList = new ObservableCollection<MyFile>();
//get the files from the folder
var filesResults = await _spFilesClient.Files[strFolderName].ToFolder().Children.ExecuteAsync();
//get the results from current page
var files = filesResults.CurrentPage.OfType<Microsoft.Office365.SharePoint.File>().ToList();
@chakkaradeep
chakkaradeep / Get File Content
Last active August 29, 2015 14:05
Office 365 API My Files - Get File Content
public static async Task<Stream> GetFileContent(string strFileId)
{
var file = (IFileFetcher)(await _spFilesClient.Files.GetById(strFileId).ToFile().ExecuteAsync());
var streamFileContent = await file.DownloadAsync();
streamFileContent.Seek(0, System.IO.SeekOrigin.Begin);
return streamFileContent;
}
@chakkaradeep
chakkaradeep / Create File
Last active August 29, 2015 14:05
Office 365 API My Files - Create File
public static async Task<MyFile> Create(string strFileName, Stream streamFileContent)
{
//MyFile is the business object
MyFile myFile = null;
//add the file to OneDrive
//file name will be the full file name along with the extension
IFile file = await _spFilesClient.Files.AddAsync(strFileName, true, streamFileContent);
if (file != null)
@chakkaradeep
chakkaradeep / Update File Entity
Created August 12, 2014 06:07
Office 365 API My Files - Update File Entity
public static async Task Update(MyFile myFile, Stream streamFileContent)
{
var file = await _spFilesClient.Files.GetById(myFile.Id).ToFile().ExecuteAsync();
file.Name = myFile.Name;
await file.UpdateAsync();
}