vrijdag 24 augustus 2012

SharePoint 2010: custom markup styles

How to complete customize the SharePoint 2010 markup styles

 
First of all you need to specify all your styles
  • Font colors
  • Fonts
  • Font Sizes
  • Mark colors
  • Predefined Styles
  • Predefined Markup Styles
  •  
The second step: write a css with all your specified styles
I have written a complete customized markup css file. You can download it at the end of this blog post. The location of the css file doesn't matter. I put always it in de layouts folder of the SharePoint root.

maandag 20 augustus 2012

Calculate total size of SPWeb object

 

private static long GetWebSize(SPWeb web)
{
Log(
String.Format("===> Calculate the total subsite size of {0}.", web.Title));
long totalWebSize = 0;
try
{
foreach (SPFolder folder in web.Folders)
{
totalWebSize += GetFolderSize(folder);
}
foreach (SPWeb subweb in web.Webs)
{
totalWebSize += GetWebSize(subweb);
subweb.Dispose();
}
}
catch (Exception ex)
{
Log(
string.Format("===> ERROR while calculating the total web size. Error: {0}, StackTrace: {1}", ex.Message, ex.StackTrace));
}
Log(
string.Format("===> Total size of subsite {0} is: {1}", web.Title, totalWebSize.ToString()));
return totalWebSize;
}

vrijdag 10 augustus 2012

SP2010: Set rigths of custom action

Set the rights of a custom action

You can set the rights on a custom action with the property "Rights". You can see an example below.

<CustomAction
Id="{0C1B0CCF-DCF6-4FCB-85E0-2CE401C17085}"Location="Microsoft.SharePoint.StandardMenu"GroupId="SiteActions"Title="Nieuwe pagina"Description="Maak een pagina aan in de bedrijfsstijl"ImageUrl="_layouts/1043/styles/img/logo_klein.png"Rights="AddAndCustomizePages"RequireSiteAdministrator="FALSE"><
UrlAction Url="~site/_Layouts/CreatePage.aspx"/></
CustomAction>

This property is needed if you want to set minimal rights to execute your custom action.
A nice list of the available rights for custom actions:

donderdag 9 augustus 2012

Add jQuery library to a webpart via code

How to load your jQuery library at the same time as your webpart?

Add the jQuery library reference via code to your webpart.

protected override void Render(HtmlTextWriter writer)
{
 writer.AddAttribute(HtmlTextWriterAttribute.Src, "/_layouts/1043/STYLES/myUZA/js/jquery-1.4.2.min.js");
 writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/javascript");
 writer.RenderBeginTag(HtmlTextWriterTag.Script);
 writer.RenderEndTag();
}

Another option is to do it in a full javascript block. You write the javascript code, put it in a string and register the javascript block via C# code:

//Load the jQuery library if it's not yet loaded
string js = @"<script type=""text/javascript"">
<">if (typeof jQuery == 'undefined') {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '/_layouts/1043/STYLES/myUZA/js/jquery-1.4.2.min.js';
document.getElementsByTagName('head')[0].appendChild(script);
}
</script>"
;

/// Register the javascript block
if
(!Page.ClientScript.IsClientScriptBlockRegistered(jsKey))
{
this.Page.ClientScript.RegisterClientScriptBlock(GetType(), "jQueryLib", js, false);
}

 

woensdag 8 augustus 2012

SharePoint 2010: Document Library - Group By expand on item click

Expand group by clicking on the item


To expand for example group Categorie by clicking on Aankoop. We need to write a jQuery function and call that jQuery function in a Content Editor webpart on the page where the ListViewWebpart is located.

vrijdag 6 juli 2012

SP2010 Sequential Workflow Send Email

Send Email in a sequential workflow


Create a Send Email task activity on your workflow.

Don't forget to set the CorrelationToken to the same token as your workflow! See earlier post. 

The code behind of that task is:

SPUser siteOwner = IntranetUtility.GetSPUser(currentItem, IntranetFieldId.SiteRequest.SiteOwner);
SPUser siteBackupOwner = IntranetUtility.GetSPUser(currentItem, IntranetFieldId.SiteRequest.SiteBackupOwner);

SendEmail confirmationMail = (SendEmail)sender;
confirmationMail.To = siteOwner.Email + ";" + siteBackupOwner.Email;
confirmationMail.Subject = string.Format("Your site {0} is created", currentItem.Title);
confirmationMail.Body = "Link to created site";
 
SPUtility.SendEmail(workflowProperties.Web, true, false, confirmationMail.To, confirmationMail.Subject, confirmationMail.Body);

SP2010: Sequential Workflow Correlation Token SendEmail

Workflow Foundation Correlation Token error

Within a workflow that I was developing, there was a requirement to notify a group of SharePoint users that a lookup service had failed. This particular activity was within a parallel activity sequence. I chose to use the SendEmail activity to notify the users, but incorrectly set the Correlation Token to a new value. When testing this functionality in the workflow I received an error:

SharePoint LOG
  1. WinWF Internal Error, terminating workflow Id#
  2. System.InvalidOperationException: Correlation value has not been initialized on declaration emailToken_JobNumberCreate for activity sendEmail_JobNumberNotCreated. at System.Workflow.Activities.CorrelationService.InvalidateCorrelationToken

The correct Correlation Token for a SendMail Activity is the “Workflow” token. The reason, which is fairly obvious, is that the SendEmail activity maps to the workflow, not to a task, which would require a Task Token