Create document edit link in sharepoint

I have a document library in sharepoint that stores a Word document.

If I click on a document link, I get a dialog box with "do you want to open this file in readonly or editmode, etc." and you can open it in edit mode, change it, save it directly in the word an changes are saved in the document library.

The link to the file in the document library is as follows:

<a onfocus="OnLink(this)" 
   href="/test/DocLib2/wordtest.docx" 
   onmousedown="return VerifyHref(this,event,'1','SharePoint.OpenDocuments','')"     
   onclick="return DispEx(this,event,'TRUE','FALSE','FALSE',
            'SharePoint.OpenDocuments.3','1', 'SharePoint.OpenDocuments',
            '','','','1','0','0','0x7fffffffffffffff','','')"
>wordtest</a>

How to create this link in my own web part where I have a file name and a document library? Without just copying the above code, this would not be a good idea ...

Is there any “official” method to achieve this?

+5
source share
5

, , . , . DispEx core.js( core.debug.js). 14\Templates\Layouts\1033.

:

function DispEx(ele, objEvent, fTransformServiceOn, fShouldTransformExtension,
    fTransformHandleUrl, strHtmlTrProgId, iDefaultItemOpen, strProgId, strHtmlType, 
    strServerFileRedirect, strCheckoutUser, strCurrentUser, strRequireCheckout, 
    strCheckedoutTolocal, strPermmask)

, . , , :

  • ele - [obj]
  • objEvent - [obj]
  • fTransformServiceOn - [bool] ( ) True
  • fShouldTransformExtension - [bool] ( ) False
  • fTransformHandleUrl - [bool] ( ) False
  • strHtmlTrProgId - [string] ActiveXControl, SharePoint.OpenDocuments.3
  • iDefaultItemOpen - [int] "" " " "1"
  • strProgId - [string] ActiveX
  • strHtmlType [] ( )
  • strServerFileRedirect - [] ( )
  • strCheckoutUser [string] ,
  • strCurrentUser - [string]
  • strRequireCheckout - [string] , .
  • strCheckedoutTolocal - [string] ""
  • strPermmask - [string] 0x7fffffffffffffffff

. , 17 , 15 , , . - JavaScript, Microsoft.

, , - .

+10

return DispEx(this,event,'TRUE','FALSE','FALSE', 
'SharePoint.OpenDocuments.3','1', 'SharePoint.OpenDocuments','','','',
'1','0','0','0x7fffffffffffffff','','')

, .

, , .

+1

, javascript #. , , , .

private string GetFileViewScript(SPFile file)
    {
        string text = SPUtility.MapToControl(SPContext.Current.Web, file.Name, string.Empty);
        string text2 = (file.Item.ParentList.DefaultItemOpen == DefaultItemOpen.Browser) ? "1" : "0";
        SPFieldLookupValue sPFieldLookupValue = file.Item["CheckedOutUserId"] as SPFieldLookupValue;
        string scriptLiteralToEncode = (sPFieldLookupValue == null) ? string.Empty : sPFieldLookupValue.LookupValue;
        string text3 = (SPContext.Current.Web.CurrentUser != null) ? SPContext.Current.Web.CurrentUser.ID.ToString(CultureInfo.InvariantCulture) : string.Empty;
        string text4 = file.Item.ParentList.ForceCheckout ? "1" : "0";

        return string.Format(CultureInfo.InvariantCulture, "return DispEx(this,event,'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}')", new object[]
        {
            "TRUE",
            "FALSE",
            "FALSE",
            text,
            text2,
            text,
            string.Empty,
            string.Empty,
            SPHttpUtility.EcmaScriptStringLiteralEncode(scriptLiteralToEncode),
            text3,
            text4,
            (string)file.Item["IsCheckedoutToLocal"],
            (string)file.Item["PermMask"]
        });
    }

DispEx SharePoint

+1

, JavaScript COM, ASP.NET HyperLink . ,

<asp:HyperLink ID="EditHl" runat="server" Text="Edit document"/>

- -

EditHl.Attributes["attribute name"] = "attribute value";

OOTB,

/test/DocLib2/wordtest.docx

URL .

0

DispEx Chrome, div, , app:

<div class="ms-vb  itx" ctxname="ctx19" id="2" app="ms-word">
    <a onfocus="OnLink(this)" 
       href="/test/DocLib2/wordtest.docx" 
       onmousedown="return VerifyHref(this,event,'1','SharePoint.OpenDocuments','')"     
       onclick="return DispEx(this,event,'TRUE','FALSE','FALSE',
            'SharePoint.OpenDocuments.3','1', 'SharePoint.OpenDocuments',
            '','','','1','0','0','0x7fffffffffffffff','','')">wordtest</a>
    <span class="ms-newdocument-iconouter">
        <img class="ms-newdocument-icon" src="/_layouts/15/images/spcommon.png?rev=23" alt="new" title="new">
    </span>        
</div>

Either you need to wrap it in such a div, and be sure to insert the desired application that will open the file, or create your own list by looking at the file extension:

$('.test_links').click(function(e) {
    e.preventDefault();
    if (!!window.chrome) {
        var extenstion = this.href.substr(this.href.lastIndexOf('.') + 1);
        var prefix = '';
        switch (extenstion) {
            case 'doc':
            case 'docx':
                prefix = 'ms-word:ofv|u|';
                break;
            case 'xls':
            case 'xlsx':
                prefix = 'ms-excel:ofv|u|';
                break;
        }
        window.location.href = prefix + this.href;
    } else {
        DispEx(this, e, 'TRUE', 'FALSE', 'FALSE', 'SharePoint.OpenDocuments.3', '0', 'SharePoint.OpenDocuments', '', '', '', _spPageContextInfo.userId + '', '0', '0', '0x7fffffffffffffff');
    }
});
0
source

All Articles