【问题标题】:Unable to open Microsoft Office files in Office client from SharePoint online 2013无法从 SharePoint Online 2013 在 Office 客户端中打开 Microsoft Office 文件
【发布时间】:2016-07-29 21:41:19
【问题描述】:

我们有 SharePoint Online 2013 网站,它显示不同部门的报告。所有部门都有不同的组,并且他们以这种方式分配了权限,因此一个组无法查看其他组文件。我正在使用 JAVA SCRIPT 和 AJAX 从图库中获取文件。当我在我的页面上使用 JavaScript 时,我无法在客户端应用程序中打开文档,它在办公室在线打开,而不是用户必须下载。无论如何用户都可以点击它,它会下载文件。我进入库设置并将默认设置更改为在客户端应用程序中打开,也更改了网站集和功能,但 SharePoint 仍然在线打开文件而不是客户端应用程序。我们使用的是 Office 2010 和 SharePoint Online 2013。

(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("");
}

【问题讨论】:

    标签: javascript json ajax sharepoint sharepoint-online


    【解决方案1】:

    我没有可以测试的环境,但这与您的 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

    THispost 提供解决方案,直接下载

    对不起,我无法测试

    祝你好运

    干杯 真实的

    【讨论】:

    • 如果我希望他们以只读方式打开或在他们自己的桌面上下载,他们可以进行更改而不影响存储在 SharePoint 上的主文件。
    • 查看第二个链接以获取有关如何下载文件的信息,这只是对您的 HTML 的一个小调整。
    猜你喜欢
    • 1970-01-01
    • 2014-08-04
    • 2016-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多