Skip to content
Loading
Sharepoint page is showing along with the addIn  
  •   
  •   
  •  
  • Nanddeep Nachan
    Tried this code on my environment and it does not display whole SharePoint site in an iframe.
    Do you have any additional script running on the site?  
  • Hi Nanddeep Nachan thaks for your response I have given the code below.
     
    1. <%@ Page Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" MasterPageFile="~masterurl/default.master" Language="C#" %>  
    2.   
    3. <%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>  
    4. <%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>  
    5. <%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>  
    6.   
    7.   
    8. "head" runat="server">  
    9.     "AllowFraming" runat="server" />  
    10.   
    11.     "text/javascript" src="../Scripts/jquery-1.9.1.min.js">  
    12.     "text/javascript" src="/_layouts/15/MicrosoftAjax.js">  
    13.     "text/javascript" src="/_layouts/15/sp.runtime.js">  
    14.     "text/javascript" src="/_layouts/15/sp.js">  
    15.   
    16.     "text/css">  
    17.         #tabledocuments th {  
    18.             text-align: center;  
    19.             border: 1.5px solid #eae8e8;  
    20.             border-collapse: collapse;  
    21.             font-size: 14px;  
    22.         }  
    23.   
    24.         #tabledocuments td {  
    25.             text-align: center;  
    26.             border: 1.5px solid #eae8e8;  
    27.             border-collapse: collapse;  
    28.             font-size: 14px;  
    29.         }  
    30.   
    31.         #tableSubsites th {  
    32.             text-align: center;  
    33.             border: 1.5px solid #eae8e8;  
    34.             border-collapse: collapse;  
    35.             font-size: 14px;  
    36.         }  
    37.   
    38.         #tableSubsites td {  
    39.             text-align: center;  
    40.             border: 1.5px solid #eae8e8;  
    41.             border-collapse: collapse;  
    42.             font-size: 14px;  
    43.         }  
    44.       
    45.     "text/javascript">  
    46.         var hostweburl;  
    47.         var appweburl;  
    48.         $(document).ready(function () {  
    49.             debugger;  
    50.             //Get the URI decoded URLs.  
    51.             //hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));  
    52.             //appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));  
    53.             var hostweburleee = window.location.protocol + "//" + window.location.host + _spPageContextInfo.webServerRelativeUrl;  
    54.             //hostweburl = _spPageContextInfo.siteAbsoluteUrl;  
    55.             appweburl = _spPageContextInfo.webAbsoluteUrl;  
    56.             if (_spPageContextInfo.siteAbsoluteUrl.indexOf('-') > -1);  
    57.             {  
    58.                 var hypenIndex = _spPageContextInfo.siteAbsoluteUrl.indexOf('-');  
    59.                 var periodIndex = _spPageContextInfo.siteAbsoluteUrl.indexOf('.');  
    60.                 var removeStr = _spPageContextInfo.siteAbsoluteUrl.substring(hypenIndex, periodIndex);  
    61.                 hostweburl = _spPageContextInfo.siteAbsoluteUrl.replace(removeStr, '');  
    62.             }  
    63.   
    64.             // resources are in URLs in the form:  
    65.             // web_url/_layouts/15/resource  
    66.             var scriptbase = hostweburl + "/_layouts/15/";  
    67.             // Load the js files and continue to the successHandler  
    68.             $.getScript(scriptbase + "SP.RequestExecutor.js", getListsFromRootSite);  
    69.             ResizeIFrame();  
    70.   
    71.         })  
    72.   
    73.   
    74.         function ResizeIFrame() {  
    75.             if (window.parent == null)  
    76.                 return;  
    77.             var senderId = $("#RequestContext_SenderId").val();  
    78.             var height = $("#form1").height();  
    79.             var width = $("#form1").width();  
    80.             var message = " + senderId + " >"  
    81.             + "resize(" + width + "," + height + ")";  
    82.             window.parent.postMessage(message, document.referrer);  
    83.         }  
    84.   
    85.         function getListsFromRootSite() {  
    86.             try {  
    87.                 debugger;  
    88.                 //SP.AppContextSite('" + hostweburl + "')/  
    89.                 var executor = new SP.RequestExecutor(appweburl);  
    90.                 console.log(appweburl + "/_api/SP.AppContextSite(@target)/Web/lists?@target='" + hostweburl + "'&$filter=BaseTemplate eq 101&$expand=RootFolder");  
    91.                 executor.executeAsync(  
    92.                 {  
    93.                     url: appweburl + "/_api/SP.AppContextSite(@target)/Web/lists?$filter=BaseTemplate eq 101&$expand=RootFolder&@target='" + hostweburl + "'",  
    94.                     method: "GET",  
    95.                     headers: {  
    96.                         "Accept""application/json; odata=verbose"  
    97.                     },  
    98.                     async: false,  
    99.                     success: SuccessHandler,  
    100.                     error: errorTitleHandlerXD  
    101.                 });  
    102.                 //)  
    103.             } catch (e) {  
    104.                 console.log(e);  
    105.             }  
    106.         }  
    107.   
    108.         function SuccessHandler(data) {  
    109.             try {  
    110.   
    111.                 debugger;  
    112.                 var jsonObject = JSON.parse(data.body);  
    113.                 var lists = jsonObject.d.results;  
    114.                 //var lists = data.d.results;  
    115.                 var tempValue = "General Folders

      "
      ;  
    116.                 tempValue += "";  
    117.                 lists.forEach(function (list) {  
    118.                     var itemCount = getDocumentLibrariesItemsCount(hostweburl, list.Title);  
    119.                     if (!window.location.origin) {  
    120.                         window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port : '');  
    121.                     }  
    122.                     var libraryURL = window.location.origin + list.RootFolder.ServerRelativeUrl;  
    123.                     console.log("Document URL= " + libraryURL);  
    124.                     tempValue += " + libraryURL + "'>" + list.Title + " (" + itemCount + ")";  
    125.                 });  
    126.                 tempValue += "";  
    127.                 $("#divRootSiteLibraries").html(tempValue);  
    128.                 getSubsites();  
    129.   
    130.   
    131.             } catch (e) {  
    132.   
    133.             }  
    134.         }  
    135.   
    136.         //Error with Title.  
    137.         function errorTitleHandlerXD(data, errorCode, errorMessage) {  
    138.             console.log("Could not complete cross-domain call: " + errorMessage);  
    139.             console.log(JSON.stringify(data));  
    140.         }  
    141.   
    142.         function getDocumentLibrariesItemsCount(webURL, listTitle) {  
    143.             var itemCount;  
    144.             try {  
    145.                 debugger  
    146.                 jQuery.ajax({  
    147.                     url: appweburl + "/_api/SP.AppContextSite(@target)/Web/lists/getByTitle('" + listTitle + "')?$select=ItemCount&@target='" + webURL + "'",  
    148.                     method: "GET",  
    149.                     headers: {  
    150.                         "Accept""application/json; odata=verbose"  
    151.                     },  
    152.                     async: false,  
    153.                     success: function (data) {  
    154.                         debugger  
    155.                         itemCount = data.d.ItemCount;  
    156.                     },  
    157.                     error: function (data) {  
    158.                         console.log(data);  
    159.                     }  
    160.                 });  
    161.                 return itemCount;  
    162.             }  
    163.             catch (e) {  
    164.                 console.log(e);  
    165.             }  
    166.         }  
    167.   
    168.         function getDocumentLibrariesCount(webURL) {  
    169.             var libraryCount;  
    170.             try {  
    171.                 jQuery.ajax({  
    172.                     url: webURL + "/_api/SP.AppContextSite(@target)/Web/lists?$filter=BaseTemplate eq 101&@target='" + webURL + "'",  
    173.                     method: "GET",  
    174.                     headers: {  
    175.                         "Accept""application/json; odata=verbose"  
    176.                     },  
    177.                     async: false,  
    178.                     success: function (data) {  
    179.                         debugger  
    180.                         libraryCount = data.d.results.length;  
    181.                     },  
    182.                     error: function (data) {  
    183.                         console.log(data);  
    184.                     }  
    185.                 });  
    186.                 return libraryCount;  
    187.             }  
    188.             catch (e) {  
    189.                 console.log(e);  
    190.             }  
    191.         }  
    192.   
    193.         function getSubsites() {  
    194.             try {  
    195.                 jQuery.ajax({  
    196.                     url: appweburl + "/_api/SP.AppContextSite(@target)/Web/GetSubwebsFilteredForCurrentUser(nWebTemplateFilter=-1)?$filter=WebTemplate ne 'APP'&@target='" + hostweburl + "'",  
    197.                     method: "GET",  
    198.                     headers: {  
    199.                         "Accept""application/json; odata=verbose"  
    200.                     },  
    201.                     async: false,  
    202.                     success: function (data) {  
    203.                         var icount = 1;  
    204.                         var subSites = data.d.results;  
    205.                         console.log(subSites);  
    206.                         var tempValue = "Management Lines

      "
      ;  
    207.                         tempValue += "";  
    208.                         subSites.forEach(function (site) {  
    209.                             debugger;  
    210.                             if (!window.location.origin) {  
    211.                                 window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port : '');  
    212.                             }  
    213.                             var webURL = window.location.origin + site.ServerRelativeUrl;  
    214.                             var librariesCount = getDocumentLibrariesCount(webURL);  
    215.                             if (icount == 1)  
    216.                                 tempValue += "";  
    217.                             tempValue += "" +  
    218.                                 "" + site.Title + "";  
    219.                             tempValue += " + webURL + "'>Active Issuers (" + librariesCount + ")";  
    220.                             var remainder = icount % 4;  
    221.                             if (remainder == 0)  
    222.                                 tempValue += "";  
    223.                             icount++;  
    224.                         });  
    225.                         tempValue += "";  
    226.                         $("#divSubSites").html(tempValue);  
    227.                     },  
    228.                     error: function (data) {  
    229.                         console.log(data);  
    230.                     }  
    231.                 });  
    232.             } catch (e) {  
    233.                 console.log(e);  
    234.             }  
    235.         }  
    236.   
    237.         // Function to retrieve a query string value.  
    238.         // For production purposes you may want to use  
    239.         //  a library to handle the query string.  
    240.         function getQueryStringParameter(paramToRetrieve) {  
    241.             var params =  
    242.                 document.URL.split("?")[1].split("&");  
    243.             var strParams = "";  
    244.             for (var i = 0; i < params.length; i = i + 1) {  
    245.                 var singleParam = params[i].split("=");  
    246.                 if (singleParam[0] == paramToRetrieve)  
    247.                     return singleParam[1];  
    248.             }  
    249.         }  
    250.       
    251.   
    252. "PlaceHolderMain" runat="server">  
    253.     "display: inline-block;">  
    254.         "divRootSiteLibraries" style="display: inline-block; vertical-align: top;">
      
  •         "divSubSites" style="display: inline-block; vertical-align: top;">  
  •       
  •   
  •   
  •  
  • Nanddeep Nachan
    Is it possible to share the code?