Posts tonen met het label SharePoint 2010. Alle posts tonen
Posts tonen met het label SharePoint 2010. Alle posts tonen

woensdag 24 april 2013

SharePoint 2010 Alerts

How to send daily alerts immediately in SharePoint 2010?
If you create new daily alert and want to see whether it will work or not it is not very convenient to wait 24 day until SharePoint will sent them next time. In this post I will show how to trigger summary alerts and send them when you need.
When you add a new daily alert on a list or something a new row is added to the SchedSubscriptions table into the SharePoint content database. The most important columns in this table are NotifyTime and NotifyTimeUNC. In these columns stores SharePoint the time when next time daily alert for particular list will be send.
Step 1: Get the id of the daily alert that you want to modify
SELECT * FROM SchedSubscriptions
Step 2: Copy the Id and execute the following SQL query:
declare @s datetime
declare @u datetime
set @s = CAST('2013-04-24 10:00:00.000' as datetime)
set @u = CAST('2013-04-24 07:00:00.000' as datetime)

update dbo.SchedSubscriptions
set NotifyTime = @s, NotifyTimeUTC = @u
where Id = '. . .'
Notice that the NotifyTimeUNC = NotifyTime minus 3 hours.
After that wait some time. Exact time of waiting depends on the Recurring Schedule of the Immediate Alert timerjob.

dinsdag 19 maart 2013

SharePoint 2010: Show lync presence in custom webpart

My customer asked for a contact details webpart with the feature if the contact is available on Lync or not. It isn’t difficult to get the contact details from a user profile in contrast to get the lync presence. I spend a few hours to get how it works in SharePoint 2010 and finally I found this blog post of Martin Kearn. With a little bit of fine tuning I rewrote the function to let it work with the UserProfile property instead of a SPFieldUserValueCollection.

maandag 11 maart 2013

SharePoint 2010 Contact Details WebPart

A customer asked me to write a webpart to have the possibility to show contact details of a user based on the userprofile. Someone told me that this webpart could be useful in other projects too. I reviewed my code an made it generic so it can be used in every SharePoint 2010 where are userprofiles present. It’s also expanded with localization. The webpart is available in English, Dutch and French.

woensdag 6 februari 2013

Add webparts to pages via PowerShell

This week I created some webparts. Those webparts must be added to more than 1000 pages in SharePoint. It’s an awful job to do it manually, so I created a script in PowerShell that do the job for me Glimlach

Code Snippet
  1. Add-PSSnapin Microsoft.SharePoint.PowerShell
  2. Start-SPAssignment -Global    # This cmdlet takes care of the disposable objects to prevent memory leaks
  3.  
  4. function AddCustomWebPart($web,$page,[string]$webpart_nameSpace,[string]$webpartTitle,[int]$index)
  5. {
  6.     $comment = $webpartTitle + " WebPart Added"
  7.  
  8.     $webpartmanager=$web.GetLimitedWebPartManager($page.Url,  [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
  9.     
  10.     $wpsOnPage = $webpartmanager.WebParts | % { $_ }
  11.     foreach($wp in $wpsOnPage)
  12.     {
  13.         if($wp -ne $null)
  14.         {
  15.             if($wp.Title -eq $webpartTitle)
  16.             {
  17.                 Write-Host "webpart " $wp.Title " exists on page. "
  18.                 $webpartmanager.DeleteWebPart($webpartmanager.WebParts[$wp.ID]);
  19.             }
  20.         }
  21.     }
  22.     
  23.     $webpart = new-object $webpart_nameSpace
  24.     $webpart.ChromeType = [System.Web.UI.WebControls.WebParts.PartChromeType]::Default;
  25.     $webpart.Title = $webpartTitle
  26.     $webpart.Width = "300px"
  27.     
  28.     $webpartmanager.AddWebPart($webpart, "RightColumn", $index);    
  29. }
  30.  
  31. function CheckInAndPublishPage($comment)
  32. {
  33.     " Checking in page"
  34.     $page.CheckIn($comment)
  35.  
  36.     # Publish
  37.     if($page.listItem.ParentList.EnableMinorVersions -eq $true -and $publishingPage.ListItem.File.MinorVersion -ne 0)
  38.     {
  39.             " Publishing"
  40.             $page.listItem.File.Publish($comment)
  41.     }
  42.  
  43.     # If moderation is being used handle the approval    
  44.     if ($page.listItem.ParentList.EnableModeration)
  45.     {
  46.  
  47.         $modInformation = $page.listItem.ModerationInformation
  48.         
  49.         " Moderation on, Current Status: " + $modInformation.Status
  50.  
  51.         # Check for pending approval
  52.         if($modInformation.Status -ne [Microsoft.SharePoint.SPModerationStatusType]::Approved)
  53.         {
  54.             " Approving"
  55.             $page.ListItem.File.Approve($comment)
  56.         }
  57.     }
  58. }
  59.  
  60. $webUrl = "http://intranet/sites/subweb/"
  61. $web = Get-SPWeb $webUrl
  62.     
  63. $list = $web.Lists["Pagina's"]
  64. Write-Host $list.Title
  65. $pages = $list.Items
  66.  
  67. foreach($item in $pages)
  68. {
  69.     $page =  [Microsoft.SharePoint.Publishing.PublishingPage]::GetPublishingPage($item)
  70.     Write-Host "Page Url: " $item.Url
  71.     Write-Host "Page ContentType: " $item.ContentType.Name
  72.     
  73.     $page.CheckOut()
  74.         
  75.     AddCustomWebPart $web $page "SharePoint.Intranet.WebParts.Bijlagen" "Bijlagen" 3
  76.     AddCustomWebPart $web $page "SharePoint.Intranet.WebParts.ProcesbeschrijvingBijlagen" "Procesbeschrijving bijlagen" 4
  77.     
  78.     CheckInAndPublishPage("Bijlage webparts toegevoegd.")
  79. }
  80.  
  81. # Clean up
  82. $web.Close()
  83.  
  84. Write-Host Done.
  85.  
  86. # Add an empty line
  87. Write-Host ""
  88.  
  89. # Clean up
  90. Write-Host "Cleaning up..."
  91. Stop-SPAssignment -Global
  92. Remove-PsSnapin Microsoft.SharePoint.PowerShell
  93.  
  94. Write-Host "Press any key to continue ..."
  95. $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

Isn’t it wonderful? The script also check if the webpart is already on the page or not. If it’s already added than it will be deleted and added again to respect the order of the webparts. For some reason SharePoint doesn’t respect the order.

If someone knows why SharePoint ignores the order of the webparts feel free to let me know.

dinsdag 8 januari 2013

SPListItemCollection with Linq

I like to use linq to find, sort, .. items in a list quick and easily, but it’s a pain to convert a SPListItemCollection into a generic list. Today I wrote a class that do the conversion for me easily.

Code Snippet
  1. public class SPListItemCollectionAdapter : List<SPListItem>
  2.     {
  3.         private SPListItemCollection _listItemCollection;
  4.  
  5.         /// <summary>
  6.         /// Get a generic list of SPListItems and convert it
  7.         /// </summary>
  8.         /// <param name="listItemCollection">SPListItemCollection collection of items</param>
  9.         public SPListItemCollectionAdapter(SPListItemCollection listItemCollection)
  10.         {
  11.             _listItemCollection = listItemCollection;
  12.  
  13.             Refresh();
  14.         }
  15.  
  16.         /// <summary>
  17.         /// Convert a SPListItemCollection into a generic list
  18.         /// </summary>
  19.         private void Refresh()
  20.         {
  21.             this.Clear();
  22.  
  23.             foreach (SPListItem item in _listItemCollection)
  24.             {
  25.                 this.Add(item);
  26.             }
  27.         }
  28.     }

Now you can use the class above like:

Code Snippet
  1. private SPListItemCollectionAdapter GetItems(SPList list, string query)
  2.         {
  3.             SPQuery q = new SPQuery();
  4.             q.Query = query;
  5.  
  6.             return new SPListItemCollectionAdapter(list.GetItems(q));
  7.         }

The only thing you need to do is declare a variable of the type SPListItemCollectionAdapter and create a new one.

Isn’t it easy?

dinsdag 18 december 2012

SharePoint 2010: Hiding the Recently Modified on Team Sites

I was asked today about hiding the Recenlty Modified menu from the quicklaunch of SharePoint 2010 Team Sites.

image

SharePoint 2010: Expand the User Profile info by default

Out of the box, the SharePoint 2010 User Profile page uses a bit of JavaScript to truncate the user’s info like Email, School etc. with a “more information” hyperlink that can be clicked to show all the info.  The user’s description text is also similarly semi-hidden on page load.

The following quick CSS hack can make both these detail areas fully visible by default, and also hide the “more information” / “hide information” hyperlink”:

SharePoint 2010: minimal.master

When you create a custom minimal.master it’s also required to have all the placeholders defined. We already know this from the v4.master but why are they needed when they are not used? They are necessary for the edit mode of the minimal masterpage. When you edit a minimal masterpage and you have only defined the minimal.master placeholder you get error messages like “Cannot find ContentPlaceHolder ‘PlaceHolderLeftNavBar’ in the master page '~masterurl/default.master', verify content control's ContentPlaceHolderID attribute in the content page.”

List of all the required ContentPlaceHolders:

woensdag 5 december 2012

SharePoint list view group by content type

By default it’s not possible to group your list items by contenttype. After some research on internet I founded a solution on codeplex:

SharePoint 2010 ViewEdit Group By Content Type

Actually it’s nothing more than adding some javascript with a script link to each page.

vrijdag 16 november 2012

Images from picture library not displayed in IE

Today I discovered a strange behavior in Internet Explorer. I  uploaded some images to my image library and I referred to them in my custom aspx page. All the images displayed correctly except one. In Firefox everything rendered correctly, in IE only the thumbnail and the web image was available. The full image was not available and I received a red cross on my page.

Conclusion: the image was corrupt!

donderdag 15 november 2012

How to use SharePoint’s default modal popup from code behind?

A while ago I needed to create a shopping basket. When you click on an item in that basket it would be nice if that item opens in a modal popup. But how can you access the default SharePoint modal popup dialog if it isn’t in your masterpage?

I used following code:

public static class Helper
{
    public static string GetDialogURL(string url, bool refreshOnClose, double width, double height)
    {
        string str = string.Concat(new object[]
		{
            "SP.UI.ModalDialog.showModalDialog({ url:'",
			url,
			"',tite: 'Move Documents',allowMaximize: true ,showClose: true,width:",
			width,
			",height:",
			height
		});
        if (refreshOnClose)
        {
            str += ",dialogReturnValueCallback: function(dialogResult){SP.UI.ModalDialog.RefreshPage(dialogResult)}";
        }
        str += "});";
        return str;
    }
    public static string GetDialogURL(string url)
    {
        return Helper.GetDialogURL(url, true, 700.0, 800.0);
    }
}

maandag 12 november 2012

XSL template to obtain all visible fields in Content Query WebPart

When we are editing XSLT for Content Query WebPart, XSLTListViewWebPart or any other WebPart with configurable XSLT, you can obtain all list fields and their values with following template:
<xsl:template name="ShowXML" match="Row[@Style='ShowXML']" mode="itemstyle">
    <xsl:variable name="SafeLinkUrl">
      <xsl:call-template name="OuterTemplate.GetSafeLink">
        <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="DisplayTitle">
      <xsl:call-template name="OuterTemplate.GetTitle">
        <xsl:with-param name="Title" select="@Title"/>
        <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
      </xsl:call-template>
    </xsl:variable>
    <b>
      Item: <i>
        <a href="{$SafeLinkUrl}" title="{@LinkToolTip}">
          <xsl:value-of select="$DisplayTitle"/>
        </a>
      </i>:
    </b>
    <ol>
      <xsl:for-each select="@*">
        <xsl:sort select="name()"/>
        <li>
          <xsl:value-of select="name()" />
          <xsl:text disable-output-escaping="yes"> </xsl:text>
          <i>
            <xsl:value-of select="."/>
          </i>
        </li>
      </xsl:for-each>
    </ol>
    <br />
  </xsl:template>

Notice that @ is the beginning char of any list field.

woensdag 7 november 2012

SharePoint 2010 Search Center MasterPage with navigation

It’s hard to navigate from a Search Center, so I decided to modify the minimal masterpage to allow you to show the topnavigation of the page. It will also show the site icon and breadcrumb navigation just like the v4.master does.

Minimal masterpage with navigation

woensdag 31 oktober 2012

SharePoint 2010 Branding: what’s publishing masterpage all about

It’s a real disaster to start branding with the default v4.master. It’s much easier when everything is commented and outlined like it should be. That’s what I did today.

v4.master

Enjoy it!

donderdag 25 oktober 2012

Set ribbon smaller via CSS

Thanks to my colleague (Laurent Schoenaers) for following css:

body #s4-ribbonrow {background-color: #FFA113; margin-top: -20px;}
.ms-siteactionsmenuinner {background:transparent;background-color:#FFA113;border-color:#FFA113;}
.ms-cui-topBar2 {border-bottom:0px;}
.ms-cui-TabRowRight {margin-top: -12px !important; padding-top: 36px !important;}
.ms-cui-ribbonTopBars div {border-bottom:1px solid transparent;}
.s4-trc-container-menu {margin:0;} 



before:


before_ribbon


after:


after_ribbon

woensdag 24 oktober 2012

SharePoint 2010 template for Photoshop

Did they ever asked you to create a SharePoint design? A design in the sense of a webdesign. Then I have a nice solution!
You can download below the default SharePoint 2010 team site design in photoshop format. Every part is created in a layer.
SharePoint 2010 design assets

RichHtmlField for custom field not rendering HTML

I had multiple RichHtmlFields on my page, and one was displaying correctly while another was not.  When I viewed the fields via the powershell, I noticed a difference in the SchemaXML, the WORKING field had the following additional properties:

     RichText="True"
     RichTextMode="FullHtml"

I found a script to update the problem field, and the problem went away for me (look below for script). The change has to be made at the list level for it to take affect on existing pages/lists, but I believe making the modification to the column at the root web (or correct subweb) would work as well.     
     $web = $site.OpenWeb($site.RootWeb.ID)
     $list = $web.Lists["Pages"]
     [Microsoft.SharePoint.Publishing.Fields.HtmlField]$field =   [Microsoft.SharePoint.Publishing.Fields.HtmlField]$list.Fields.GetFieldByInternalName("PageContentFld")
     $field.RichText = $true
     $field.RichTextMode = [Microsoft.SharePoint.SPRichTextMode]::FullHtml
     $field.Update()
     $list.Update()

You may want to check your field to make sure those properties are set.


donderdag 6 september 2012

Trigger resize event with jQuery cross-browser

Bind an event handler to the "resize" JavaScript event, or trigger that event on an element

jQuery has a built-in method for this:

$(window).resize(function () { /* do something */ }); 

For the sake of UI responsiveness, you might consider using a setTimeout to call your code only after some number of milliseconds, as shown in the following example, inspired by this:

function doSomething() { 
alert("I'm done resizing for the moment");
};

var resizeTimer;
$(window).resize(function() {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(doSomething, 100);
});

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.

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: