Wednesday 30 March 2016

Fix SharePoint scrolling problems for Chrome

<script>
    function FixWorkspace() {
        // if you are using a header that is affixed to the top (i.e. SharePoint Ribbon) put the ID or class           // here to change the workspace height accordingly.
        var header = '#myHeader';
        var width = $(window).width();
        var height;
        if ($(header).length) {
            height = $(window).height() - $(header).height();
        } else {
            height = $(window).height();
        }
        $('#s4-workspace').width(width).height(height);
    }

    $(document).ready(function () {
        FixWorkspace();
    });

    $(window).resize(function () {
        FixWorkspace();
    });
</script>

Wednesday 17 February 2016

SharePoint COM to get all image with more than specified size.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
namespace the the ConsoleApplication1
{
    class Program
    {
        static void Main ( string [] args)
        {
            string Webappurl = "http://abc.com/sites/123" ;
            using ( var ctx = new ClientContext (Webappurl))
            {

                ListItemCollectionPosition Pos = null ;
                while( true )
                {
                    DocumentsList list  = Ctx.Web.Lists.GetByTitle ( "Test" );
                    ListItemCollection results = documentsList.GetItems (CreateAllFilesQuery (pos));
                    ctx.Load (documentsList);
                    Ctx.Load (results, items => Items.ListItemCollectionPosition, items =>Items.Include (item => item [ "File_x0020_Size" ], item => item [ "FileRef" ]));
                    ctx.ExecuteQuery ();
                    // Get item position
                    pos = results.ListItemCollectionPosition;
                    foreach( var result in results)
                    {
                     double size = ConvertBytesToMegabytes ( Convert .ToInt64 (result [ "File_x0020_Size" ]));
      Console .WriteLine (result [ "FileRef" ] + "->" + Size.ToString () + "MB" );
                    }
                    // End where there is no items available
                    if(pos == null )
                        break ;
                }
                Console .Read ();
            }
        }

        public static CamlQuery CreateAllFilesQuery (ListItemCollectionPosition pos)
        {
            var qry = new CamlQuery ();
            string Rowlimit = "100" ;
            // Query to get only files and not folder (FSObjType will be 1 for folder)
            qry.ListItemCollectionPosition = pos;
            // 2097152 - which specified to get only images with more than 2MB of size
    qry.ViewXml =  "<View Scope = \" RecursiveAll \ "> <ViewFields> <FieldRef Name = 'FileRef' />                           <FieldRef Name = 'File_x0020_Size' /> </ ViewFields> <RowLimit>" + Rowlimit + "</                       RowLimit> <Query> <Where> <And> <Eq> <FieldRef Name = \ "FSObjType \" /> <Value                         Type = \ "Integer \"> 0 </ Value> </ Eq> <And> <Geq> <FieldRef Name = \                                 "File_x0020_Size \ " /> <Value Type = \ "Lookup \"> 2097152 </ Value> </ Geq> <Or>                     <Eq> <FieldRef Name = \ "File_x0020_Type \" /> <Value Type = 'Text'> jpg </ Value>                     </ Eq> <Or> <Eq> <FieldRef Name = \ "File_x0020_Type \" /> <Value Type = 'Text'>                       png </ Value> </ Eq> <Eq > <FieldRef Name = \ "File_x0020_Type \" /> <Value Type =                     'Text'> jpeg </ Value> </ Eq> </ Or> </ Or> </ And> </ And> </ Where> < / Query> </                     View> " ;
            return qry;
        }

        public static double ConvertBytesToMegabytes ( long bytes Download now)
        {
            return (bytes Download now / 1024f) / 1024f;
        }
    }
}