This article demonstrates how to use various methods/properties associated with SPFile object using client object model  JavaScript variation (ECMA Script).
The examples shows how to do file operations in document library using ECMA script. 

We have a document library called “Shared Documents” and its having one file which is having id =1. We will do all operation considering this file only.

So first we will try to checkout file using ECMA

File Checkout:

 Code Sample

<script language="ecmascript" type="text/ecmascript"> 
  ExecuteOrDelayUntilScriptLoaded(CheckOutFile, "sp.js");
 var list;
var item;
 var file; 

        function CheckOutFile() {
            var clientContext = SP.ClientContext.get_current();            
                var webSite = clientContext.get_web();
                this.list = webSite.get_lists().getByTitle("Shared Documents");
                this.item = list.getItemById(1);
                this.file = this.item.get_file();
                clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));            
        function OnLoadSuccess(sender, args) {
            alert(this.file.get_title() + " File checked out successfully");
        function OnLoadFailed(sender, args) {
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

File Check In

this.file = this.item.get_file();
Enumeration for CheckIn type available @


 this.file = this.item.get_file();
 Method parameter
 copyTo(strNewUrl , bOverWrite )
 strNewUrl : It must be a URL of relative or absolute form.
 bOverWrite:  Specifies whether a file with the same name is overwritten.


 this.file = this.item.get_file();
 this.file.moveTo("/Shared%20Documents/1/ TestFile.htm",1);

This operation moves file with complete version information/history.

Publish File

 this.file = this.item.get_file();
 this.file.publish("Published Major Version");


Delete File

 this.file = this.item.get_file();

Get File Path

 this.file = this.item.get_file();

Get document Author Name

 this.file = this.item.get_file();

It provides author login name,title,email  etc

Get document Modified By Name

 this.file = this.item.get_file();

It provides login name,title,email and other details of the user who has modified the file.

Here is the complete list of methods provided by SharePoint JavaScript client object model API for SPFile object.