Posts

Showing posts with the label SPServices

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, ...

SharePoint Get Current Web URL

How to get SharePoint site current URL ? We can get SharePoint Current web url in Server-Side as well as in Client side. Server Side:  As we all know current web url can be accessed in server side by web object as below. SPContext.Current.Web.Url Client Side: In client side , we can achieve this by using  SPServices  . Here is how to achieve this: Include SPServices js file in your page. Now you can access the url this way: var thisWebUrl = $().SPServices.SPGetCurrentSite(); But there is a bug in recent versions of SPServices , where the above method will return only "/". But in SharePoint 2013, we  can access web url as below as well : var thisWebUrl = _spPageContextInfo.webAbsoluteUrl; (web url) var thisSiteUrl = _spPageContextInfo.siteAbsoluteUrl; (site url) Enjoy coding :)

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, '');     $().SPServices({         operation: "CopyIntoItems",         webURL: getCurrentUrl(),         processData: false,         async: false,         SourceUrl: "http://null",         Stream: strm,         DestinationUrls: [getCurrentUrl() + "DocumentLibraryName/file.txt"],         completefunc: function (xData, Status) {         ...