获取当前Word文档的OneDrive项目ID [英] Get OneDrive Item Id for Current Word doc

查看:203
本文介绍了获取当前Word文档的OneDrive项目ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑为Microsoft Word构建一个外接程序,该外接程序将涉及创建当前文档的副本.

I'm looking into building an add-in for Microsoft Word that would involve creating a copy of the current document.

我找到了可以通过OneDrive API 复制项目的地方.但是,这需要复制文档的项目ID.

I've found where I can copy an item through the OneDrive API. However, this requires the item-id for the document to be copied.

我似乎找不到如何通过Office JavaScript API获取当前Word文档的item-id的方法.

I can't seem to find how to get the item-id for the current Word document through the Office JavaScript API.

我查看了Office.context.document对象以及Office.context.document.getFileAsync()Office.context.document.getFilePropertiesAysnc()函数.

I've looked on the Office.context.document object, as well as the Office.context.document.getFileAsync() and Office.context.document.getFilePropertiesAysnc() functions.

有人将如何获取当前Word文档的OneDrive项目ID?

How would someone get the OneDrive Item Id for the current Word doc?

推荐答案

无法仅使用Office.js来执行此操作,您还需要利用Microsoft Graph来查找实际ID.

There isn't a way to do this using just Office.js, you'll need to also leverage Microsoft Graph in order to find the actual ID.

保存文件后,可以使用获取URI. getFilePropertiesdAsync .您需要从URI解析文档名称和路径.然后,您可以在云端硬盘的 Children 方法来隔离您要查找的特定文件.

Once you have a saved file, you can get the URI using getFilePropertiesdAsync. You'll need to parse the document name and path from the URI. You can then use query filters on the Drive's Children method to isolate the specific file you're looking for.

例如,如果您的URI为https://d.docs.live.net/<id>/Documents/somedoc.docx,则可以确定以下内容:

For example, if you had a URI of https://d.docs.live.net/<id>/Documents/somedoc.docx you can determine the following:

  • 这是消费者OneDrive(请注意live.net URI)
  • 文档名称为somedoc.docx
  • 它存储在目录Documents
  • This is consumer OneDrive (note the live.net URI)
  • The document name is somedoc.docx
  • It is stored in the directory Documents

要找到此文档,您将执行以下Graph命令:

To find this document you would execute the following Graph command:

https://graph.microsoft.com/v1.0/me/drive/root/children/Documents?$filter=name eq 'somedoc.docx'

所有这些都可以直接从您的外接程序中执行.请记住,用户可以将文档保存到OneDrive和OneDrive for Business.用户必须使用相同的凭据针对他们要保存的驱动器针对图形进行身份验证.

All of this can be executed directly from within your add-in. Please keep in mind, users can save documents to both OneDrive and OneDrive for Business. The user must authenticate against graph using the same credentials for the drive they're saving against.

这篇关于获取当前Word文档的OneDrive项目ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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