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.