Monday, April 23, 2012

SharePoint: Set Alerts on tasks list

After my shot with that script back fired a couple of days ago I needed a solution that worked. I remembered that there was a function that might work. I only tried this for the tasks list.

Open your tasks list, click on "List Settings", head over to the "Adcanced settings". You will find "E-Mail Notification" there.
When you click on "Yes", the assigned user will get an Email if something changes in his task, except if it's the description field. And of course he get's an email that a task was assigned to him.

Sunday, April 22, 2012

PowerShell: Update every list item in SharePoint

So I do have a workflow that starts, when an item has been changed. And i got a list with many items, which need an update to get the workflow started. Instead of clicking on every item, I decided to write a little script, to create an update on every item.
$web=get-SPWeb "YOURWEB"
foreach($item in $list.Items)
And now the workflow will run for every item.

Wednesday, April 18, 2012

PowerShell: Set SharePoint Alerts

I had to come up with a way to set user alerts without sending a notification. I completely forgot about a little function SharePoint provides, which I will post about tomorrow.
My first idea was to just use PowerShell. In the end I came up with two scripts, unfortunately the second one just won't work. But I will post it anyway, maybe it helps someone to get an idea on how to work on the subject.

The first script will get you the user who got the task assigned to. I will only take a look at the last one modified, because my workflow runs everytime an item is created or changed.

## Get user who is assigned to task
$TaskList = $web.lists["Tasks"]
$item = @($TaskList.items | Sort-Object {$_.Modified} -Descending)[0]
$users = $item["Assigned To"].split("#")
$var1 = $users[1]
$var2 = $item
The second one is the one I can't get to work. Maybe someone can sort it out and work with it. I checking the list "Tasks", where I publish all tasks and assign them. Then I want to add an alert, called "Custom Alert", but only on the last modified item.

## Create an alert without notification ##
$web = Get-SPWeb("YOURWEB)
$TaskList = $web.lists["Tasks"]$alerts = $web.Alerts
$user = $var1
$item = $var2
## Set new alert ##
$setAlert = $web.Alerts.Add()
$setAlert.Title = "Custom Alert"
$setAlert.AlertType = [Microsoft.SharePoint.SPAlertType]::Item
$setAlert.Item = @($TaskList.items | Sort-Object {$_.Modified} -Descending)[0]$setAlert.DeliveryChannels = [Microsoft.SharePoint.SPAlertDeliveryChannels]::Email
$setAlert.EventType = [Microsoft.SharePoint.SPEventType]::Add
$setAlert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Immediate
Maybe you are wondering why I'm using names such as "$var1". Well, this is because of a tool called "Nintex Workflow". They provide the function to store values through your workflow, but the names are "$varX".

SharePoint: Where did my files go?

Today a user called me asked where his file went and why SharePoint is telling him, that he can't upload it again. The error message containt a message, saying that the file is already checkout to a user.

I checked the library in SharePoint and via Windows Explorer, but the file was indeed gone. So after a while I remembered that there is another way.

Open the library settings and under the topic "Permissions and Management" choose "Manage files which have no checked in version".

And there was the file. I took over ownership and checked the file in.

Monday, April 16, 2012

SharePoint (Slide Library): Let's make this picture big!

Well, a couple of months back, I had a little run-in with Slide Libraries. A customer asked me if it's possible to resize the thumbnails or make them pop out a bit. Yes, it's possible with a little Javascript.

Here's the script and sorry for the formatting:
<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(getImages, "sp.js");
function getImages()
   $("body").append("<div style='display:none; position:absolute;' id='boxdiv'><img src=''
      id='boximg' onMouseOut='hideImageBox()' /></div>");
    var thumbimg = document.getElementsByTagName('img');
    var i = 0;
    for(i=0; i < thumbimg.length; i++)
      if(thumbimg[i].alt == 'Thumbnail')
   thumbimg[i].setAttribute('onMouseOver', 'showImageBox(this.src)');
function showImageBox(imgurl)
   var IE = document.all?true:false
   var tempX = 0;
   var tempY = 0;

   if (IE)
   { // grab the x-y pos.s if browser is IE
      tempX = event.clientX + document.getElementById("s4-workspace").scrollLeft;
      tempY = event.clientY + document.getElementById("s4-workspace").scrollTop;
   {  // grab the x-y pos.s if browser is NS
      tempX = e.pageX;
      tempY = e.pageY;
   var boxd = document.getElementById('boxdiv');
   var boxi = document.getElementById('boximg');
   boxi.src = imgurl; = "block"; = tempY; = tempX;
function hideImageBox()
   var boxd = document.getElementById('boxdiv'); = "none";
(Don't forget to add the locations of your JQuery-Sources.)
What does it do? It grabs for the tag "Thumbnail", because that's the "alt"-text of those images. Than we set a new attribute, in this case it's a "MouseOver"-effect. And this will create us the PopUp.

But how do you place this script in your library?
First edit the Page.
That add a new "Content Editor"-Webpart.
That's it. Now you should see little images of your thumbnails flying at you.

PowerShell: Split strings

Oh that's an easy one, but I always forget it after a couple of weeks. Well, I don't use it that often, but it is kind of useful. So let's split all the strings!

$URL = "http://YOURURL.TLD/site/topic
$strings = $URL.split("/")
That's how you split your strings. Now you have a couple of strings, because we split them at the "/". It may not be the smartest idea, but this way you start building the needed address the way we want it.

The result will look something like this:
$strings[0] -> http:
$strings[1] -> ~empty~
$strings[2] -> YOURURL.TLD
$strings[3] -> site
$strings[4] -> topic
But why should anybody do it that way? For example your are working with SharePoint and using the Get-SPWeb command in PowerShell, you will get the address of your web, but that may be not the address you need for a picture or a link. So now you can just edit the link you need.

In my case, I needed to do that to change the "http" to "https". I wrote a blogpost about exchanging strings, which worked fine when I had to change only links. But it wouldn't work with the pictures I implemented, which also needed an https address. And with the .split()-method I was able to recreate the address in the way I wanted it to be.

Thursday, April 12, 2012

SharePoint: Can't publish to Slide Library

I created a Slide Library for a customer, which he really liked. He was playing around on my Dev-System and also on my Test-System. Everything went better than expected so we decided to jump over and release his library for his colleagues. But unfortunatly it didn't go that well on the production system. He was working a couple of days with it and got always problems with uploading some presentation.

When I was back in the office I had to take a look into it, so I started testing with the Dev-System and of course our Test-System. But to my dissappointment it worked fine, so the problem was only somewhere in the production system.

Next thing I checked was the event log, but also nothing unusual. Some typical errors, but nothing new or in any way related to my slide library. Than I read through the SharePoint Logs while uploading a file, just in case it throws an exception or an error of any kind. But also nothing there.

So what else could it be? I took a look at the last installed patches on the systems, but also: nothing related to PowerPoint or the slide libraries.

Finally I gave up and took a look at the PPTX-files I got. Everything looked fine, but when I was running the "Inspect Document" command under "File / Info / Check for Issues" it throws an error, telling me something about "Picture crop information". It was indeed possible, that this information brought up an random error while uploading this file. I clicked the "Remove All" button, but no matter how often I clicked that button and saved the file, it always came up with the same error.

My last attempt was to save the PPTX-file a little bit old school. I decided to save the file als PPT and check out if the error still pops up while uploading. To my surprise it worked fine and I got no error, but I'm still not sure why it came up. I will keep investigating, maybe I will find a proper solution, but for now saving in PPT makes the most sense.

PowerShell: Update a Field in SharePoint

I needed to update a couple of rows from a specific list in SharePoint. The value was luckily always the same. So I wrote this little script:
Add-PSSnapin Microsoft.SharePoint.Powershell
$web=get-SPWeb "YourWeb"
foreach($item in $list.Items)
   $item["YourField"] = "YourUpdate"
I simply pick the web in which I want to work, search for my list there. In this list, I will pick my field and give it a new updated value. Don't forget to use $item.update() at the end, because otherwise your new value won't get displayed.

SharePoint: Which version or update is installed?

If you ever need a way to get the binary information of the installed SharePoint Server, you can go to the Central Administration.

Click on "Upgrade and Migration":

After that, choose "Check product and patch installation status":

On the next page you can see every binary version of the installed products on your farm or on a specific server.

Wednesday, April 11, 2012

PowerShell: Compare Dates

Today we want to compare an existing date from a SharePoint List called "Compare" with the date of today. We want to check if the date is the same or not.

So here is the code:
$web = Get-SPWeb "YourSite"
$CompareList = $web.lists["Compare"]
$CompareListItem = @($CompareList.items | sort-object {$_["Modified"]} -descending)[0]
[datetime]$Today = [datetime]::Now
[datetime]$StartTime = [datetime]$CompareListItem["Start_Time"]
if($Today.Date.CompareTo($StartTime.Date) -eq 0 )
   $result = Yes
   $result = No
What does it do?

It loads your web, than chooses a list, in this case "Compare". I decided that I only need the newest item. With "[datetime]$Today = [datetime]::Now" we will get the date of today. The next line will get us the Date-Field from the SharePoint List. Because we are using "[datetime]", we can now compare the two dates.

PowerShell: Replace (String)

Here's a simple thing in PowerShell and I guess most people already know how to replace strings. I had to come up with an idea on how to replace a piece of information in a domain address.

Here's the little script:

$web = Get-SPWeb "YourWeb"
$httpURL = $web.Url
$httpsURL = $httpURL | foreach{$_ -replace "http", "https"}

I simply take the "SPWeb" and search for "http". Everytime I get a "http" I will replace it with a "https". It's that simple.

InfoPath 2010: "Full Trust" A Form

This is an easy one, but it took me a while to find this need little feature again.
In InfoPath 2010 you will find every Form Option under "File".

So go to "File", then "Form Option", click on "Security Level" und clear the checkbox next to "Automatically determine security level" and instead select "Full Trust".

Tuesday, April 10, 2012

SharePoint 2010: Create a Slide Library

Slide Libraries are really cool to use, because you can distribute slides for your company or collegues without needing to save every slide in a single .PPT oder .PPTX file. It's also an OOB-Feature in SharePoint 2010. So let's get started on this one!

This is your typical frontpage. I created an empty SiteCollection just to show you how it could and should work.
First click on "Site Actions" and choose "More Options...".
Here you have to do a bit of scrolling and choose the "Slide Library".

Now you just have to click on that symbol and then on "Create". Finally give it a nice little name and a description and your set to go.

So, that was easy right? In the next couple of days we will take a look at what could wrong. And what did go wrong while i used it.