简体   繁体   中英

Office 365 API for SharePoint

I am very much new to Office 365 API's. I am using Microsoft.Office365.SharePoint and Microsoft.Office365.OAuth libraries to access the documents in Office 365 sharepoint site.

I am able to aunthenticate (using SiteApiSample.cs this is the sample provided by MSDN for Office 365 API's) to office 365. I am able to get the file name from sharepoint by using the below code.

public static async Task<IEnumerable<IFileSystemItem>> GetDefaultDocumentFiles()
        {
            var client = await EnsureClientCreated();
            client.Context.IgnoreMissingProperties = true;    

            // Obtain files in default SharePoint folder

            var filesResults = await client.Files.ExecuteAsync();
            var files = filesResults.CurrentPage.OrderBy(e => e.Id);
            return files;
        }

Now my intention is that, I would need to get the file content / folder content to a byte array. I have tried several ways, but did not worked. If some one has working sample with this request you to please share. Thank you.

My recommendation with anything Office 365 development is to start at http://dev.office.com/ , plenty of documentation, code samples, videos and training there.

The files API is documented here (following the documentation link) http://msdn.microsoft.com/en-us/library/office/dn605900(v=office.15).aspx .

You can get the file contents using in the REST API:

/_api/files(<file_path>)/download

or you can use the Class Libraries in the Visual Studio project like your sample above:

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;
}

To get the actual file using the files API there are some great samples by someone who wrote the tools in the visual studio team, @chakkaradeep. http://chakkaradeep.com/index.php/office-365-api-my-files-crud-sample-code/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM