19/07/2012

SharePoint Foundation 2013 Search

It appears that the lightweight search (search server express) is included in SPF 2013 with some nice additional web parts in the results interface


It also includes the refinement webparts on the left - note the timeline slider bar...NICE!

SharePoint 2013 HTML Field Security

Another nice feature of SP2013 is the ability to restrict what contributors can embed in site pages.

Under site collection settings there is an entry for HTML field security.


We can dictate what domains are safe regarding embedded content


When a user tries to embed code in an editable region they will get the following error if the domain isn't set in the HTML field security


However, note that the error tells the user of an alternate way to embed the code using the embed command.

So now if the user chooses embed from the ribbon


It appears that the HTML security is bypassed!!!!!


Definitely one to watch, especially if this still appears in the RTM version





SharePoint 2013 - New Task Lists

The task lists appears to remain much the same in SP2013
However the user interface has changed somewhat!

We now have a timeline that appears above the task list.


We can also change the colours of the task list items, something that we had to use jQuery for in the past.



We can also choose whether to display a task on the timeline


Another nice touch is the ability to indent tasks so that the list resembles MS Project


And finally the ability to open with project and sync changes back to SharePoint


*This is taken from the preview version of SP2013 and may be subject to change!

04/06/2012

Event Receivers redirect in tabular view

More event handlers and more pain!

Using a custom redirect on ItemDeleting works fine in tabular view with a SINGLE item selected.
e.g.
properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;

properties.RedirectUrl = "/_layouts/DeleteStub/stubError.aspx?errMsg=" + err;




However when we select multiple items


The event handler kicks in no problem but then the redirect fails miserably!!!



Event handlers have moved from being funky to painful over the last 12 months!


01/05/2012

SQL Fragmentation - lightweight script

The following script will iterate through all of your databases and report on the average fragmentation of your indexes for each DB.
Its less intrusive as it doesn't create any temporary tables and gives you a quick report on where fragmentation is most prevalent

DECLARE @DatabaseID smallint
DECLARE @DatabaseName varchar(255)  
DECLARE DatabaseCursor CURSOR FOR 
SELECT  dbid, name FROM master.dbo.sysdatabases  
--WHERE name NOT IN ('master','model','msdb','tempdb','distrbution')  
--ORDER BY 1 
OPEN DatabaseCursor 
FETCH NEXT FROM DatabaseCursor INTO @DatabaseID, @DatabaseName
WHILE @@FETCH_STATUS = 0 
BEGIN 
-----------------------------------------------------
  SELECT @DatabaseName as Database_Name, avg(avg_fragmentation_in_percent) as Average_Fragmentation FROM sys.dm_db_index_physical_stats (NULL, NULL, NULL, NULL, NULL)
  where avg_fragmentation_in_percent > 30 and database_id =  @DatabaseID
  
----------------------------------------------------- 
    
FETCH NEXT FROM DatabaseCursor INTO @DatabaseID,@DatabaseName
END 
CLOSE DatabaseCursor  
DEALLOCATE DatabaseCursor

26/04/2012

SharePoint SQL Fragmentation

Here a simple SQL script to show you the fragmentation of tables in your database....run it against any of the DB's in your SQL instance

Note - it creates and drops a temporary table to hold the report (fraglist)
I have set the threshold in this script to 30% fragmentation

DBCC SHOWCONTIG


/*Perform a 'USE ' to select the database in which to run the script.*/
-- Declare variables
SET NOCOUNT ON;
DECLARE @tablename varchar(255);
DECLARE @execstr   varchar(400);
DECLARE @objectid  int;
DECLARE @indexid   int;
DECLARE @frag      decimal;
DECLARE @maxfrag   decimal;

-- Decide on the maximum fragmentation to allow for.
SELECT @maxfrag = 30.0;
-- Declare a cursor.
DECLARE tables CURSOR FOR
   SELECT TABLE_SCHEMA + '.' + TABLE_NAME
   FROM INFORMATION_SCHEMA.TABLES
   WHERE TABLE_TYPE = 'BASE TABLE';
-- Create the table.
CREATE TABLE #fraglist (
   ObjectName char(255),
   ObjectId int,
   IndexName char(255),
   IndexId int,
   Lvl int,
   CountPages int,
   CountRows int,
   MinRecSize int,
   MaxRecSize int,
   AvgRecSize int,
   ForRecCount int,
   Extents int,
   ExtentSwitches int,
   AvgFreeBytes int,
   AvgPageDensity int,
   ScanDensity decimal,
   BestCount int,
   ActualCount int,
   LogicalFrag decimal,
   ExtentFrag decimal);
-- Open the cursor.
OPEN tables;
-- Loop through all the tables in the database.
FETCH NEXT
   FROM tables
   INTO @tablename;
WHILE @@FETCH_STATUS = 0
BEGIN
-- Do the showcontig of all indexes of the table
   INSERT INTO #fraglist
   EXEC ('DBCC SHOWCONTIG (''' + @tablename + ''')
      WITH FAST, TABLERESULTS, ALL_INDEXES, NO_INFOMSGS');
   FETCH NEXT
      FROM tables
      INTO @tablename;
END;
-- Close and deallocate the cursor.
CLOSE tables;
DEALLOCATE tables;
-- Declare the cursor for the list of indexes to be defragged.
DECLARE indexes CURSOR FOR
   SELECT ObjectName, ObjectId, IndexId, LogicalFrag
   FROM #fraglist
   WHERE LogicalFrag >= @maxfrag
      AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0;
-- Open the cursor.
OPEN indexes;
-- Loop through the indexes.
FETCH NEXT
   FROM indexes
   INTO @tablename, @objectid, @indexid, @frag;
WHILE @@FETCH_STATUS = 0
BEGIN
   PRINT 'TABLE FRAGMENTATION (0, TABLE:' + RTRIM(@tablename) + ',
      ' + RTRIM(@indexid) + ') - fragmentation currently '
       + RTRIM(CONVERT(varchar(15),@frag)) + '%';

   FETCH NEXT
      FROM indexes
      INTO @tablename, @objectid, @indexid, @frag;
END;
-- Close and deallocate the cursor.
CLOSE indexes;
DEALLOCATE indexes;
-- Delete the temporary table.
DROP TABLE #fraglist;
GO

JQuery for SharePoint made simpler

Here's some simple JQuery to help you avoid looking for those annoying GUID's

var list = [];
var peoplePicker1;
var peoplePicker2;
var currentObject;

$(document).ready(function() {

// use this ^ for wildcard hiding/showing all items that begin with "xxx"
$('[title^="xxx"]').closest('tr').hide();
$('[title^="xxx"]').closest('tr').show();

$('DIV[id^="sectionSection2"]').hide();

// will need this to hide date/time fields
$('nobr:contains("Hire Car")').closest('tr').hide();

// use for text fields and drop down lists
var x = $('[title$="Authoriser"]').val();

// use for radio and checkboxes
// where title$ is the choice option
$('[title$="Enter Choice #1"]').click(function() {
alert('Please ensure you complete the Tracking section');

// get the radio button id
var tmp = $(this).children('input').attr('id');

// check its value
alert($("input[id="+tmp+"]:checked").val());
var checked =  $("input[id="+tmp+"]:checked").val();
if(checked == 'on')
{
// do something
}
});

// use for people pickers
// add each people picker to an array and assign it to a var
// start loop
$(".ms-inputuserfield").each(function(){
list.push($(this).text());
currentObject = $(this);
});
// end loop
peoplePicker1 = list[0];
peoplePicker2 = list[1];
currentObject.attr('disabled','disabled');

var currentUser = $().SPServices.SPGetCurrentUser({
 fieldName: "Title",
 debug: false
});

// check if the user is an admin user
function isAdmin(user)
{
    var adminUser1 = "System Account";
    var adminUser2 = "john smith";
    var adminUser3 = "john doe";
    var adminUser4 = "dave nixon";
    var adminUser5 = "fred smith";
if(user == adminUser1 || user == adminUser2 || user == adminUser3 || user == adminUser4 || user == adminUser5)
{
return "admin";
}
else
{
return "not admin";
}
   
}
function CheckForAttachment()
{
  var elm = document.getElementById("idAttachmentsTable");
  if(elm == null || elm.rows.length == 0)
  {
    alert("No e-training form attached");
    return false;
  }
  else { return true; }
}
function PreSaveAction()
{
  return CheckForAttachment();
}




});