2016-04-08 91 views
0

我們有SharePoint Online 2013網站,該網站顯示不同部門的報告。所有部門都有不同的組,並且他們已經以這種方式分配了權限,因此一個組不能看到其他組文件。我使用JAVA SCRIPT和AJAX從圖庫中獲取文件。當我在我的頁面上使用JavaScript時,我無法打開客戶端應用程序中的文檔,它在網上打開的辦公室比用戶不得不下載。無論如何,用戶可以點擊它並下載文件。我去圖書館設置,並更改了默認打開客戶端應用程序也改變了網站集和功能,但仍然打開文件在線而不是客戶端應用程序。我們在2013年使用Office 2010和SharePoint。無法在Office 2013中從Office SharePoint客戶端打開Microsoft Office文件

(function() { 


    // Create object that have the context information about the field that we want to change it's output render 
    var galleryContext = {}; 
    galleryContext.Templates = {}; 


    galleryContext.Templates.Header = "<div class='gallery'>"; 
    galleryContext.Templates.Footer = "</div><div class='gallerydocs'></div>"; 


    // This line of code tell TemplateManager that we want to change all HTML for item row render 
    galleryContext.Templates.Item = galleryTemplate; 

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(galleryContext); 

})(); 

// This function provides the rendering logic 
function galleryTemplate(ctx) { 
    var icon = ctx.CurrentItem["GalleryIcon"]; 
    var src = ctx.CurrentItem["FileRef"]; 
    var name = ctx.CurrentItem["Title"]; 
    var subtitle =ctx.CurrentItem["SubTitle"]; 
    var bgcolor = ctx.CurrentItem["BackgroundColor"]; 
    var fontcolor = ctx.CurrentItem["FontColor"]; 

    //var description = ctx.CurrentItem["Description"]; 
// console.log(JSON.stringify(ctx.CurrentItem["GalleryIcon"])); 
    // Return whole item html 
    return "<div onclick='javascript:getGalleryDocs("+'"'+ src + '"' +", "+'"'+ bgcolor + '"' +", "+'"'+ subtitle + '"' +", "+'"'+ fontcolor + '"' +", "+'"'+ name + '"' +")'><div class='galleryblock' style='background-color:" + bgcolor + ";color:"+ fontcolor+"' >"+name +"<br/><br/><p>"+subtitle +"</p></div></div>"; 
} 


function getGalleryDocs(folder , bgcolor, subtitle ,fontcolor , name) 
{ 

$.ajax({ 
     url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/GetFolderByServerRelativeUrl('"+folder+"')/files?$orderby=Title", 
     method: "GET", 
     headers: { "Accept": "application/json; odata=verbose" }, 
     success: function (data) { 
     var html="<div class='gallerynav'><span><a href='javascript:goback();'>BILLING REPORTS</a><span> <i class='fa fa-caret-right' ></i><span>"+name+"</span></div><div class='galleryblock' style='float:none;background-color:" + bgcolor + ";color:"+ fontcolor+"' >"+name +"<br/><br/><p>"+subtitle +"</p></div><span></span>"; 
     var results = data.d.results; 
     //console.log(JSON.stringify(results.length)); 
     html+= "<ul class='gallerylinks'>"; 
     if(results.length > 0) 
     { 
      for(i=0 ; i< results.length ; i++) 
      { 
       var item = results[i]; 
       html+= "<li><a href='" + item.LinkingUrl + "' target='_blank'>"+item.Title+"&nbsp;&nbsp;<i class='fa fa-external-link'></i></a></li>"; 
      } 
     } 
     else 
     { 
      html+="&nbsp;&nbsp;&nbsp;THERE ARE NO DOCUMENTS IN THIS GALLERY" 
     } 
     html+="<ul>" 
     //console.log(JSON.stringify(data)); 
     $(".gallery").hide(500); 
     $(".gallerydocs").html(html); 

     }, 
     error: function (data) { 
      $(".gallerydocs").html("You dont have permissions to view this folder!") 
     } 
     }); 
} 
function goback(){ 
$(".gallery").show(500); 
     $(".gallerydocs").html(""); 
} 

回答

0

我還沒有一個手動測試這個環境,但它將與您的href鏈接有關。它需要以不同的方式構建。下面的解決方案有望在客戶端應用程序中打開。

嘗試

<a href="" 
    onclick="editDocumentWithProgID2('http://server/site/doclib/folder/Document.docx', 
    '', 
    'SharePoint.OpenDocuments', '0', 
    'http://server/site', '0')"> 
    This will open the file in edit mode 
</a> 

完整後可以發現here

THis後提供了一個解決方案,直接下載

對不起,我不能測試

好運

乾杯 Truez

+0

如果我希望它們以只讀方式打開或在自己的桌面上進行下載,它們可以進行更改,而不會影響存儲在SharePoint上的主文件。 – James

+0

查看第二個鏈接,瞭解如何下載該文件的信息,再一次對HTML進行一些調整。 – Truezplaya

相關問題