使用客户端对象模型仅从文档库下载每个文档的第一页 [英] Download only the first page of each document from Document Library using Client Object Model

查看:77
本文介绍了使用客户端对象模型仅从文档库下载每个文档的第一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有包含文件的文件库。我编写了一个客户端对象模型来下载文档。但我想 知道。我不想下载整个文档,而只想下载每个文档的第一页。下载整个文件后我应该
不拆分第一页。在下载时,我应该只获得文档的第一页。

I have document library which contains documents. I have written a Client Object model to download the document. But I would like  to know. Instead of downloading the entire document, I want to download only the first page of each document. I should not split the first page after download entire file. While download itself, I should get only first page of the document.

是否可以?

问候

Poomani Sankaran

Poomani Sankaran

推荐答案

嗨Suresh,

Hi Suresh,

我理解文件是否是Word文件,然后想要下载单词的第一页。

I understand if the document is a Word file, then want to download the first page of the word.

根据我的测试,这是不可能的,因为从下载文件时库,我们用File.OpenBinaryDirect方法得到整个文件流,如下所示:

Per my test, it is not possible, as when downloading the document from library, we are getting the whole file stream with File.OpenBinaryDirect method like below:

internal static void DownloadFilesFromSharePoint(string siteUrl, string folderPath, string tempLocation)
{
    ClientContext ctx = new ClientContext(siteUrl);
    ctx.Credentials = new SharePointOnlineCredentials(Username, Password);

    FileCollection files = ctx.Web.GetFolderByServerRelativeUrl(folderPath).Files;

    ctx.Load(files);
    ctx.ExecuteQuery();

    foreach(File file in files)
    {
        FileInformation fileInfo = File.OpenBinaryDirect(ctx, file.ServerRelativeUrl);
        ctx.ExecuteQuery();

        var filePath = tempLocation + file.Name;
        using (var fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
        {
            fileInfo.Stream.CopyTo(fileStream);
        }
    }
}

在文件流中,我们无法拆分第一页流,因为这个原因,我们可以不能直接从CSOM代码获得第一页。

In the file stream, we can't split the first page stream, as this reason, we can't get only first page directly from CSOM code.

谢谢

最好的问候


这篇关于使用客户端对象模型仅从文档库下载每个文档的第一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆