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

My previous post Save string content as a file in Document Library from Client Side explains how to add a string content as a file in SharePoint document Library.
This post just extends the previous post. Suppose you have a metadata column in document library which describes some metadata about the file.
For example there is a column called "FileInfo" which will describe some information about the file. So now we need to pass value to this column while adding the file.
Let us see how this can be done.
function AddFileToDocumentLibrary(str) {
    var strm = Base64.encode(str);
    strm = strm.replace(/ /g, '');
    $().SPServices({
        operation: "CopyIntoItems",
        webURL: getCurrentUrl(),
        processData: false,
        async: false,
        SourceUrl: "http://null",
        Stream: strm,
        Fields: "<FieldInformation Type='Text' DisplayName='FileInfo' InternalName='FileInfo'  Value='This File Contains Contact Information' />",
        DestinationUrls: [getCurrentUrl() + "DocumentLibraryName/Contact.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 + "/";
}
In the above code as you can see the option Fields allows us to provide values to the columns in the List/Library.
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 :)

Comments

  1. This is also a very good post which I really enjoyed reading. It is not every day that I have the possibility to see something like this..

    notepad ++ download mac

    ReplyDelete

Post a Comment

Popular posts from this blog

SharePoint Online (O365) OAuth Authentication | Authorizing REST API calls against SharePoint Online Site | Get Access token from SharePoint Online | Set up OAuth for SharePoint Online Office 365

SharePoint 2013 REST API Reference

Simple Risk Assessment Matrix table with resultant risk calculation

Kendo UI (Core JavaScript) grid Server Paging, Server Sorting and Server Filtering with Dynamic SQL queries

Sharepoint- Using an Image From formatmap32x32.png in a Ribbon Control