Sharepoint托管应用模型控件不显示

时间:2016-06-03 05:18:08

标签: asp.net sharepoint sharepoint-2010 office365 office365-apps

在定制共享点网站时,我们使用了Share-point Hosted App Model。我在使用App Model时遇到了一个问题。

以下是我所做的步骤。

  1. 使用Visual Studio创建了一个Share-point Hosted App Model。
  2. 创建应用程序时,会有内置文件名为App.js和default.aspx
  3. App.js文件中的代码将获取当前上下文,并在default.aspx中存在的p标记内显示当前登录人名。
  4. 此时我收到了用户名,我可以在p标签内看到它。
  5. 在default.aspx中,我添加了文本区域,按钮,文本框等控件,构建成功,我部署了解决方案。
  6. 现在,在我的共享点网站上,我创建了一个新页面并添加了应用程序部分,但未在我的页面中显示。它显示为
  7. enter image description here

    中的代码

    AppManifest文件

    <AppPrincipal>
    <Internal/>
    </AppPrincipal>
    <AppPermissionRequests AllowAppOnlyPolicy="false">
    <AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="Manage" />
    </AppPermissionRequests>
    

    Default.aspx的

     <%@ Page Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" MasterPageFile="~masterurl/default.master" Language="C#" %>
    
        <%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
        <%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
        <%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    
        <%-- The markup and script in the following Content element will be placed in the <head> of the page --%>
        <asp:Content ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
            <script type="text/javascript" src="../Scripts/jquery-1.9.1.min.js"></script>
            <SharePoint:ScriptLink name="sp.js" runat="server" OnDemand="true" LoadAfterUI="true" Localizable="false" />
            <meta name="WebPartPageExpansion" content="full" />
    
            <!-- Add your CSS styles to the following file -->
            <link rel="Stylesheet" type="text/css" href="../Content/App.css" />
    
            <!-- Add your JavaScript to the following file -->
            <script type="text/javascript" src="../Scripts/App.js"></script>
        </asp:Content>
    
        <%-- The markup in the following Content element will be placed in the TitleArea of the page --%>
        <asp:Content ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server">
            Page Title
        </asp:Content>
    
        <%-- The markup and script in the following Content element will be placed in the <body> of the page --%>
        <asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
    
            <div>
                <p id="message">
                    <!-- The following content will be replaced with the user name when you run the app - see App.js -->
                    initializing...
                </p>
        <input type="text" id="txtApprove" name="txtApprove"/>
        <input type="button" value="Approve" id="btnApprove" name="btnApprove"/>
            </div>
    
        </asp:Content>
    

    App.js

    'use strict';
    
    ExecuteOrDelayUntilScriptLoaded(initializePage, "sp.js");
    
    function initializePage()
    {
        var context = new SP.ClientContext("/sites/sitename");
        var user = context.get_web().get_currentUser();
        var oListItem;
        // This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
        $(document).ready(function () {        
            getUserName();
            UpdateWFStatusColumn(58);
        });
    
        // This function prepares, loads, and then executes a SharePoint query to get the current users information
        function getUserName() {
            context.load(user);
            context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail);
        }
    
        // This function is executed if the above call is successful
        // It replaces the contents of the 'message' element with the user name
        function onGetUserNameSuccess() {
            $('#message').text('Hello ' + user.get_title());
        }
    
        // This function is executed if the above call fails
        function onGetUserNameFail(sender, args) {
            alert('Failed to get user name. Error:' + args.get_message());
        }
    
        function UpdateWFStatusColumn(itemId) {
            var web = context.get_web();
            var oList = web.get_lists().getByTitle('EmpList');
            oListItem = oList.getItemById(itemId);
            oListItem.set_item('ApprovalStages', 'Approval');
            oListItem.update();
            context.load(oListItem);
            context.executeQueryAsync(
                function (sender, args) {
                    alert("Workflow started");
                },
                function (sender, args) {
                    alert("Failed to load subscription.");
                    alert("Error: " + args.get_message() + "\n" + args.get_stackTrace());
                }
                );
        }
    }
    

0 个答案:

没有答案