sharepoint - 如果 Document-CT 在常规 SharePoint 文档库中具有自定义表单,则无法更改 Office 文档的内容类型
问题描述
这似乎是 SharePoint 处理 Office 文档的一个错误:如果内容类型具有自定义表单,我们无法更改 SharePoint 文档库中的 Microsoft Office 文档内容类型。
复制步骤:
- 在 SharePoint 网站中创建新文档库
- 激活内容类型,添加任何第二个内容类型(例如图片)
- 将空白 Excel 或 Word 文件上传到库中,
- 更改默认内容类型的表单(文档,请参见下面的示例代码)
- 尝试更改文档的内容类型 - 更改无效
如果您上传任何其他文件,例如 txt 或 pdf,您可以按预期更改内容类型。
您可以使用以下 JavaScript 代码从浏览器开发工具的 allitems.aspx 视图中自定义 SharePoint 中的表单:
const spWebUrl = _spPageContextInfo.webAbsoluteUrl; // assuming to be on a SharePoint AllItems.aspx list-view page
const docLibId = _spPageContextInfo.listId; // assuming to be on a SharePoint AllItems.aspx list-view page
const testCtId = '0x010100B68D7A00400FB34BA1A31C9ABBB97168'; // GET THE ID OF THE DEFAULT-CONTENT-TYPE ("Document") FROM THE LIBRARY SETTINGS PAGE
const formUrl = _spPageContextInfo.webServerRelativeUrl + '/SitePages/TestForm.aspx'; // custom form location
// to switch to custom forms, uncomment the following line:
setFormsForCT(spWebUrl, docLibId, testCtId, formUrl, formUrl, formUrl);
// check the console and network tab output whether the operation was successful
// to restore standard forms, uncomment the following line:
//restoreFormsForCT(spWebUrl, docLibId, testCtId);
async function setFormsForCT(webUrl, listId, ctId, dispFormUrl, editFormUrl, newFormUrl) {
await fetch(`${webUrl}/_api/web/lists('${encodeURIComponent(listId)}')/contenttypes('${encodeURIComponent(ctId)}')`, {
method: 'POST',
headers: {
'Accept': 'application/json; odata.metadata=minimal',
'Content-type': 'application/json; charset=utf-8',
'X-HTTP-Method': 'MERGE', // updating
'IF-MATCH': '*',
'X-RequestDigest': _spPageContextInfo.formDigestValue, // assuming valid and defined
},
body: JSON.stringify({
"DisplayFormUrl": dispFormUrl,
"EditFormUrl": editFormUrl,
"NewFormUrl": newFormUrl
}),
});
}
async function restoreFormsForCT(webUrl, listId, ctId) {
return setFormsForCT(webUrl, listId, ctId, "", "", "");
}
其他人,看到同样的问题吗?
任何解决方法,除了删除和恢复自定义表单以更改内容类型?
解决方案
推荐阅读
- javascript - 如何使用钩子更新后加载反应值
- regex - 具有 .00 数字格式的正则表达式范围
- openldap - 如何将openldap服务器中具有pwdchangedtime的用户导出到另一个openldap服务器
- html - 使用 CSS 标记的自定义文本
- prolog - 从列表中获取一组元素(Prolog)
- spring-boot - Kotlin 协程观察者
- flutter - 如何保存 TextField 用户输入
- javascript - 当项目有键时 Firebase 更新或添加值
- python - 两个集合不相等,但在转换为列表并转换回集合后相等
- java - 无法从 Firestore 获取数据