The CreateAnonymousLink method creates an anonymous link with option either to read or edit. It is quite useful to share documents with external users.
The drawback is that anyone with the link can view/edit the document shared without sign-in.
The method “CreateAnonymousLink ” accomplishes the same as “View Link – no sign-in required” and “Edit Link -no sign-in required” from the UI.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Test.CreateAnonymousLink = (function() | |
{ | |
var ctx = SP.ClientContext.get_current(); | |
var restSource = _spPageContextInfo.webAbsoluteUrl + "/_api/SP.Web.CreateAnonymousLink"; | |
alert(restSource); | |
$.ajax( | |
{ | |
'url': restSource, | |
'method': 'POST', | |
'data': JSON.stringify({ | |
'url': _spPageContextInfo.webAbsoluteUrl + '/Shared Documents/CRM Dynamics 2015 key.txt', | |
'isEditLink': true | |
}), | |
'headers': { | |
'accept': 'application/json;odata=verbose', | |
'content-type': 'application/json;odata=verbose', | |
'X-RequestDigest': $('#__REQUESTDIGEST').val() | |
}, | |
'success': function (data) { | |
alert(data.d.CreateAnonymousLink); | |
}, | |
'error': function (err) { | |
alert(JSON.stringify(err)); | |
} | |
} | |
); | |
} | |
); |
Once the link is generated, it can be sent by email to the relevant individuals.