SharePoint: Save string content as a file in Document Library from Client Side.

This Post explains you how to Save a string content as a file in SharePoint Document Library.
Refer this Post if you want to pass value to a column as well SharePoint: Save string content as a file in Document Library from Client Side with a metadata column
Use the below javascript code: (include SPService reference.)

function AddFileToDocumentLibrary(str) {
    var strm = Base64.encode(str);
    strm = strm.replace(/ /g, '');
        operation: "CopyIntoItems",
        webURL: getCurrentUrl(),
        processData: false,
        async: false,
        SourceUrl: "http://null",
        Stream: strm,
        DestinationUrls: [getCurrentUrl() + "DocumentLibraryName/file.txt"],
        completefunc: function (xData, Status) {
             alert("Status=" + Status);
function getCurrentUrl() {
    var thisSite = $().SPServices.SPGetCurrentSite(); //if this line of code doesn't give you the url, try commenting this line and uncommenting the below line.
    //var thisSite = _spPageContextInfo.siteAbsoluteUrl;
    return thisSite + "/";
Please don't forget to incluse SPServices js file ans jquery.Base64.min.js (create a js file with this name and copy js code from here how-to-encode-and-decode-strings-with-base64-in-javasript) file.

Happy coding :)

Vikas Kottari

Hi. I’m a SharePoint Developer. I’m Microsoft Certified Professional on SharePoint. I work on O365, SharePoint 2016/2013/2010, SPFx and also I’m Full stack .NET Developer. I’m Foodie, Dreamer and Photographer. Inspired to make things looks better.