简体   繁体   English

用于SharePoint的Office 365 API

[英]Office 365 API for SharePoint

I am very much new to Office 365 API's. 我是Office 365 API的新手。 I am using Microsoft.Office365.SharePoint and Microsoft.Office365.OAuth libraries to access the documents in Office 365 sharepoint site. 我正在使用Microsoft.Office365.SharePoint和Microsoft.Office365.OAuth库来访问Office 365共享点站点中的文档。

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. 我能够取消疲劳(使用SiteApiSample.cs,这是MSDN为Office 365 API提供的示例)到Office365。我可以使用以下代码从共享点获取文件名。

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. 对于任何Office 365开发,我的建议是从http://dev.office.com/开始,那里有大量的文档,代码示例,视频和培训。

The files API is documented here (following the documentation link) http://msdn.microsoft.com/en-us/library/office/dn605900(v=office.15).aspx . 此处记录了文件API(通过文档链接) http://msdn.microsoft.com/zh-cn/library/office/dn605900(v = office.15.aspx

You can get the file contents using in the REST API: 您可以使用REST API获取文件内容:

/_api/files(<file_path>)/download

or you can use the Class Libraries in the Visual Studio project like your sample above: 或者您可以像上面的示例一样在Visual Studio项目中使用类库:

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. 为了使用files API获得实际文件,有一些很好的示例,这些示例是由Visual Studio团队@chakkaradeep编写的。 http://chakkaradeep.com/index.php/office-365-api-my-files-crud-sample-code/ http://chakkaradeep.com/index.php/office-365-api-my-files-crud-sample-code/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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