HTML页面中的Sharepoint上下文信息

时间:2016-01-25 14:25:28

标签: javascript angularjs sharepoint

我通过将javascript和html文件上传到文档库,在Sharepoint 2013中构建SPA。我试图通过sp.js库访问上下文信息来获取当前用户信息。但是我得到了这个错误:

_spPageContextInfo is not defined

在我的index.aspx文件中,我包含以下js:

<script src="/_layouts/1033/init.js"></script>
<script src="/_layouts/MicrosoftAjax.js"></script>
<script src="/_layouts/sp.core.js"></script>
<script src="/_layouts/sp.runtime.js"></script>
<script src="/_layouts/sp.js"></script>

我还将它包含在index.aspx文件的顶部:

<%@ Page language="C#" %>
<%@ Register Tagprefix="SharePoint"
 Namespace="Microsoft.SharePoint.WebControls"
 Assembly="Microsoft.SharePoint, Version=14.0.0.0, 
 Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint" %>

在我的js文件中,我有以下代码:

$(document).ready(function() {
  // wait for the sharepoint javascript libraries to load, then call the function 'Initialize'
  ExecuteOrDelayUntilScriptLoaded(runCode, "sp.js");   
});
function runCode() {
    var userid= _spPageContextInfo.userId;
}

应该提到我使用Angular JS构建应用程序,并使用Angular UI路由器库在页面之间导航。

文档库位于侧面集合中的子网站内。

E.g。

intra.xxx.xxx/xxx/index.aspx

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

事实证明,我显然在我的index.aspx文件中缺少一些sharepoint依赖项。

<强>解决方案

开始index.aspx:

<%@ Page language="C#" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<!DOCTYPE html>

标题中的脚本:

<!--Sharepoint Dependencies-->
    <script src="/_layouts/1033/init.js"></script>
    <script src="/_layouts/1033/core.js"></script>
    <script src="/_layouts/MicrosoftAjax.js"></script>
    <script src="/_layouts/SP.Core.js"></script>
    <script src="/_layouts/SP.Runtime.js"></script>
    <script src="/_layouts/SP.js"></script>
    <script src="/_layouts/SP.UI.Dialog.js"></script>
    <script src="/_layouts/ScriptResx.ashx?culture=en%2Dus&name=SP%2ERes"></script>

体:

<!-- required: SharePoint FormDigest -->
<form runat="server">
  <SharePoint:FormDigest runat="server"></SharePoint:FormDigest>
</form>