Thursday, June 12, 2014

Check in file using Client script


Share/Save/Bookmark

Here is a simple way of doing few file operations in sharepoint using client script. You can try JQuery for client object model or CSOM or JQuery with SPServices(in my case).

function DiscardCheckOut(url)
{

    var errorMessage = "";

    $().SPServices({
    operation: "UndoCheckOut",
    async: false,
    pageUrl: url,
    completefunc: function (xData, Status) {
         $(xData.responseXML).find("errorstring").each(function() {
         errorMessage = $(this).text();
         });

        $(xData.responseXML).find("faultstring").each(function() {
               errorMessage += $(this).text();
         });

        var undoCheckOutVal= $(xData.responseXML).find("UndoCheckOutResult").text();
        if(undoCheckOutVal == "true")
             alert("Operation success");
        else
            alert("Operation failed:"+errorMessage);
     }
});

}

function CheckIn(furl)
{

   var errorMessage = "";

   $().SPServices({
   operation: "CheckInFile",
   async: false,
   pageUrl: furl,
   comment': "Checked in from checkout list",
   CheckinType: 1,
   completefunc: function (xData, Status) {
       //get errorstring
        $(xData.responseXML).find("errorstring").each(function() {
             message = $(this).text();
        });

       //get fault string
       $(xData.responseXML).find("faultstring").each(function() {
            message +=" "+ $(this).text();
       });

      var checkInResultVal= $(xData.responseXML).find("CheckInFileResult").text();
      if(checkInResultVal == "true")
            alert("Check-in operation success");
      else
            alert("Operation failed:"+errorMessage);
   }
   });
}



Subscribe

Ribbon Tab with id: "Ribbon.Read" has not been made available for this page or does not exist. Use Ribbon.MakeTabAvailable()

Share/Save/Bookmark

‘The Ribbon Tab with id: "Ribbon.Read" has not been made available for this page or does not exist. Use Ribbon.MakeTabAvailable()’

Have you seen that crazy error on your page? Don't worry its not your fault but a riddle left by MSFT. I'm certain that you got this error when playing with wiki pages. Yes, if wiki pages are rendered in IFrame or wiki page url has IsDlg=1(as part of querystring) this error shows up in sharepoint logs. As a quick around you can change the type of the page from wiki to webpart. But, if you are reluctant to do so then jump to a custom solution for a fix.
 
Subscribe

List Checkout documents using search

Share/Save/Bookmark

Today im gonna show you an easiest OOTB approach using search(with no coding) to list/display all checked out documents(across webapp/site collections) to current user. Based on the result sources/content source configured on sharepoint farm, search query can be run on wider scope of data.

Configure content search webpart with the below query(copy paste in query text box) in advanced mode. 

 CheckoutUserOWSUSER:{User.Name} {contentclass:STSListItem OR IsDocument:True}

Subscribe

List shared with me in SkyDrive

Share/Save/Bookmark

Skydrive does seems to have a feature, shared with me that will allow users to see all the documents shared only with them. This is available only in office365/cloud version of sharepoint and is not with Sharepoint on-premise.

When digging into on-premise mysite features, found a page,sharedwithme.aspx under personal/ADid/documents/forms. Here, documents is nothing but a special library used for skydrive for the user. This library will have all the documents added by you and shared with you or by others. Sharedwithme.aspx(acting like a view) will show the documents shared with current user. Looking at the view, with missing values for the columns(shared by/modified) and column header mismatch with actual datatable its easy to say that this feature is not completely functional. I'm not sure if this is ever meant to be found or working. Also, there is no OOTB way to have the left navigation link for sharedwithme view. Though, this can be added using jquery but a lot of work(not sure how far feasible) need to be done to the OOTB sharedwithme webpart used on this view. So, i changed the strategy and built it using content search webpart.Below is the search query i used to configure content search webpart to fetch all shared items with current user.

IsMyDocuments:1 IsDocument -Author:{User.Name} -SharedWithInternal:"NT AUTHORITY\Authenticated Users"

IsMyDocuments is used to identify all documents from skydrive(mydocuments). Above query will filter out all the documents authored by current user and show only shared with him/her.

Few weeks after this implementation, MS has released OneDrive for business. I did'nt get a chance to review its features but worth to look at it before doing this.

Subscribe