Wednesday, December 7, 2011

SharePoint 2010: Hide The "Quicklaunch" Bar

1. Create a "Content Webpart" somewhere on your SharePoint Page. If you want to hide it the moment the page loads, place it above your other content.
2. Add this code:
<style type="text/css">
.s4-leftpanel
{
display:none;
}
.s4-ca
{
margin-left:0px;
}
</style>

Tuesday, December 6, 2011

SharePoint 2010: Hide The "Recent Modified" Bar

This is really simple.

1. Create a "Content Webpart" somewhere on your SharePoint Page. If you want to hide it the moment the page loads, place it above your other content.
2. Add this code:
<style type="text/css">
.s4-recentchanges
{
display:none;
}
</style>


If you want to hide it for all pages

1. Go to  "Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Template\DocumentTemplates"
3. Search for the tag "SharePoint:RecentChangesMenu"
4. Add "visible=true" at the tags end.
If you hit save and reload the page, it won't show the "Recent Modified" menu anymore.

Wednesday, March 30, 2011

JQuery: Creating A Slider

So... a customer had a little problem with a slider in SharePoint. I had no idea what she was talking about, but i thought that this might be interesting.
I google searched about the slider functions in jquery, which are indeed very nice. After playing around for a while I finally came up with this little slider, see code below.
<!DOCTYPE html>
<html>
<head>
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
    <style type="text/css">
    #slider
    {
        margin: 10px;
        float: left;
        clear: left;
        width: 300px;
        margin: 15px;
    }
    #slider .ui-slider-range { background: #ef2929; }
    #slider .ui-slider-handle { border-color: #ef2929; }

    </style>

  </style>
  <script type="text/javascript">
      $(document).ready(function()
      {
            $("#slider").slider(
        {
            enable: true,
            animate: true,
            max: 100,
            min: 0,
            step: 1,
            range: "min",
            orientation: "horizontal",
            slide: function(event, ui)
            {
                    $("#amount").val(ui.value+'%');
                }
        });
        $("#amount").val($("#slider").slider("value")+ '%');
      });


  </script>
</head>
<body style="font-size:62.5%;">
    <div id="slider">
    </div><br>
    <input type="text" id="amount" style="border:0; color:#000000; font-weight:bold;" />
</body>
</html>


But what does actually happen here? It isn't that hard to explain, but hard to search for solutions all over the internet.
To begin with, just implement your sources for JQuery:
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

And with this little piece of code you adjust your css:
#slider
    {
        margin: 10px;
        float: left;
        clear: left;
        width: 300px;
        margin: 15px;
    }
    #slider .ui-slider-range { background: #ef2929; }
    #slider .ui-slider-handle { border-color: #ef2929; }

Until now nothing happens. Let's take a look why the slider slides to the left and to the right.

There is a lot of stuff in this function. First of all you call the slider function from JQuery.
$(document).ready(function()
      {
            $("#slider").slider(
        {
            enable: true,
            animate: true,
            max: 100,
            min: 0,
            step: 1,
            range: "min",
            orientation: "horizontal",
            slide: function(event, ui)
            {
                    $("#amount").val(ui.value+'%');
                }
        });
        $("#amount").val($("#slider").slider("value")+ '%');
      });

This little piece is the configuration of the slider:
enable: true,
Display the value.
animate: true,
Animate the slider instead of letting it jump from start to the choosen point.
max: 100,
The max value.
min: 0,
The max value.
step: 1,
Size of the steps, which are able to take.
range: "min",
This is needed to color the bar.
orientation: "horizontal",
display a horizontal bar.

slide: function(event, ui)
            {
                    $("#amount").val(ui.value+'%');
                }
        });
        $("#amount").val($("#slider").slider("value")+ '%');
This function is simply to display the value which is selected.



And that's that. Now you can slide all day long. The value will not be stored anywhere, so after a refresh it's gone.

Thursday, March 3, 2011

Substrings & C#

To things simple, I decided that every value I'm writing in my "ContentField" will end with ", ". But this also happens with the last element. It doesn't look that good, that's why I want to cut it off.
And here's my solution:
int strlength = ContentField.Length;
string strend = ContenField.Substring(strlength - 2);
if (strend == ", ")
{
    strlength = strlength -2;
}
ContentField = ContentField.Substring(0, strlength);
I need the length of the string, in this case: the length of  "ContentField". To keep things shorter, I want to write that value into a new variable:
int strlength = ContentField.Length;
 The only interesting part in that string are the last too letters, so I'm creating a substring, only viewing the last 2 characters:
string strend = ContenField.Substring(strlength - 2);
The rest ist simple: compare the string to the characters, cut them off and post the new string.
ContentField = ContentField.Substring(0, strlength);
In this case I decided that the start of my substring is 0, this is the first character. and the end of my string will be defined by "strlength".

XPathNavigator & InfoPath 2010 using C#

So, back on the job and back to many problems. This time it really bugged me a bit.
I'm working on an InfoPath 2010 form, which needs some "tweaking" beyond the possibilities provided by rules implemented in InfoPath 2010.

Just as an example: I need to be able to set textfields or move their content easily. I want to be able to send the values from different checkboxes to a textfield. The checkbox is called "CheckMe" and is a boolean field. 1 means it is checked, 0 it isn't.
But how can I use these fields from InfoPath 2010? The answer is: XPathNavigator & XmlNamespaceManager.

Here's the code I'm using:

XPathNavigator xnPath = this.CreateNavigator();
XmlNamespaceManager xnNS = this.NamespaceManager;
string ContentField;
ContentField = xnPath.SelectSingleNode("//my:myFields/ContentField", xnNS).Value;
string CheckMe = xnPath.SelectSingleNode("//my:myFields/CheckMe").Value;
if (CheckMe == "1")
{
   ContentField = ContentField + "CheckMe";
}
What happens there?
XPathNavigator xnPath = this.CreateNavigator();
First of all I'm defining my "XPathNavigator" which will point to a part of my InfoPath form.

XmlNamespaceManager xnNS = this.NamespaceManager;
Here I'm creating my own new NamepaceManager, which is need in InfoPath 2010 while using C#.
Still, I'm not working with any fields. For that I gonna use this little line:
xnPath.SelectSingleNode("//my:myFields/ContentField", xnNS)
Now I'm pointing to the field I want to modify. This is a bit too long to remember, that's why I'm creating a new variable.
ContentField = xnPath.SelectSingleNode("//my:myFields/ContentField", xnNS).Value;
I need ".Value" to send the  to my variable, which in this case is a string. And now: here's the part where I'm manipulation the textfield.

if (CheckMe == "1")
{
   ContentField = ContentField + "CheckMe";
}
If the checkbox "CheckMe" is true, which means "checked", I want to write "CheckMe" into my textfield.

Saturday, February 19, 2011

JavaScript: Open Links In A New Window

Again, I got a little problem at work. Someone decided that it would be funny to "play" with the settings. So: We aren't able to open links in a new window, which kinda like sucks often.

Here's the code, again with an explanation below.


<script language="JavaScript">
_spBodyOnLoadFunctionNames.push("rLink");
function rLink()
{
    var anchors = document.getElementsByTagName("a");
    for (var x=0; x<anchors.length; x++)
    {
      if (anchors[x].outerHTML.indexOf('#onw')>0)
      {
        oldText = anchors[x].outerHTML;
        newText = oldText.replace(/#onw/,'" target="_blank');
        anchors[x].outerHTML = newText;
      }
    }
}
</script>
What's going on there?
This part, "_spBodyOnLoadFunctionNames.push("rLink");" , makes sure that the function "rLink" will be loaded when the page is opening.
First off all "var anchors = document.getElementsByTagName("a");" we are searching for all links and are writing them into our array "anchors".
Now we have to search through the array for our tag, which in this case is "#onw".
If a link got that tag, this little friend will do the trick:

oldText = anchors[x].outerHTML;
newText = oldText.replace(/#onw/,'" target="_blank');
anchors[x].outerHTML = newText;

We are now saving the link into another variable "oldText", than we just cut off our tag and open the link in a new window.

But remember: if you want to open a link in a new window, you have to but the "#onw" tag behind that link.

Sunday, February 13, 2011

JavaScript: Automatischer Seitenwechsel

Vor einiger Zeit kam mein Chef zu mir und fragte nach einem kleinen Feature in SharePoint". Er hat das schlichtweg "Bildschirmschoner" genannt. Im ersten Moment dachte ich, er macht Witze. Natürlich hab ich ihm dann mitgeteilt das er die Bildschirmschoner von Windows nutzen soll. Aber: er wollte ein kleines "Tool" das es seiner SharePoint Seite erlaubt nach einer gewissen Zeit automatisch eine neue Seite aufzurufen.

Am Ende kam ich dann mit dem Code unten an, welcher überraschender weise gut funktionierte.

Hier der Code, Erklärung gibts unten drunter.
<html>
  <head>
    <script language="javascript" type="text/javascript">
      var addresses = new Array();
      /* fill array */
      var startt = 100000;
      var activ = window.setTimeout("Show()", startt);
      var length = 4;
      function SetTimer()
      {
        try
        {
          window.clearTimeout(activ);
          activ = window.setTimeout("Show()", startt);
        }
        catch(e)
        {
          window.status = "Error: " + e.number + "; " + e.description ;
        }
      };
      function Show()
      {
        var i = Math.floor(Math.random()*length);
        document.location = addresses[i];
      };
    </script>
  
  </head>
  <body onload="SetTimer()">
  </body>
</html>

Was passiert hier eigentlich?
<body onload="SetTimer()">
Das ist noch einfach: Beim Aufruf der Seite wird die Funktion "SetTimer()" aufgerufen.
 Und hier ist die Funktion auch schon:
function SetTimer()
      {
        try
        {
          window.clearTimeout(activ);
          activ = window.setTimeout("Show()", startt);
        }
        catch(e)
        {
          window.status = "Error: " + e.number + "; " + e.description ;
        }
      };
Der letzte Abschnitt ist klar: Jede Fehlermeldung soll in der Statusleiste des Browsers angezeigt werden.
Dann mal auf zum Hauptteil..Um sicher zu gehen das meine Variable "activ" nicht schon einen Inhalt hat, lasse ich diese mit "clearTimeout" löschen.
Aber wie starte ich den Counter wieder? Hierfür nehme ich die Funktion "setTimeout", welche eine Funktion zum Aufruf und eine Zeitangabe in Millisekunden benötigt. Nach Ablauf der Zeit wird die Funktion "Show()" aufgerufen..
Und damit sind wir auch schon beim eigentlichen Problem: innerhalb "Show()" werde ich die Seiten wechseln lassen. Endlich.

Der Einfachheit halber lasse ich nur 4 Elemente in meinem Array "addresses" zu. Der erste Schritt ist nun eine Zufallszahl zu generieren. Dafür nutze ich "Math.floor(Math.random()*length). "Floor" rundet die Zahlen nur nächsten geraden  Zahl ab. "Random" bietet uns eine Zahl zwischen 0 und 1 an. Um eine Nummer zwischen 1 und 4 zu erhalten muss ich das Ergebnis von Random mit der Länge meines Arrays multiplizieren, in dem Fall 4.

Nun haben wir die Zufallszahl "i". Aber was machen wir damit?
Einfach: Wir ändern die Adresse in der Adressleiste mit "document.location = addresses[i];". Der 2. Teil wählt das Element aus dem Array aus, das an der Stelle "i" steht. Der erste Teil schreibt die Adresse dann in die Adressleiste.

Und schon sind wir fertig. Die Seite wird nun alle paar Minuten die Seite wecheln.

Saturday, February 12, 2011

JavaScript: Automated Page Switching

So, one day I got stuck at work. My boss told me to give his SharePoint site a new little feature. He called it "screen saver". At first I thought he was kidding, I told him to use the ones which come with Windows. But he meant that he needs a little "tool" that will automatically switch through his pages after a couple of minutes.

In the end I came up with a little idea, which indeed worked pretty well.

Here is the code, I will explain it below:
<html>
  <head>
    <script language="javascript" type="text/javascript">
      var addresses = new Array();
      /* fill array */
      var startt = 100000;
      var activ = window.setTimeout("Show()", startt);
      var length = 4;
      function SetTimer()
      {
        try
        {
          window.clearTimeout(activ);
          activ = window.setTimeout("Show()", startt);
        }
        catch(e)
        {
          window.status = "Error: " + e.number + "; " + e.description ;
        }
      };
      function Show()
      {
        var i = Math.floor(Math.random()*length);
        document.location = addresses[i];
      };
    </script>
  
  </head>
  <body onload="SetTimer()">
  </body>
</html>
What's happening there?

<body onload="SetTimer()">
This one is simple: start the function called "Set Timer" when the page is loaded.
 Here's the function we will call:
function SetTimer()
      {
        try
        {
          window.clearTimeout(activ);
          activ = window.setTimeout("Show()", startt);
        }
        catch(e)
        {
          window.status = "Error: " + e.number + "; " + e.description ;
        }
      };
The last part is obvious: display every error in the window status bar.
So, just let us take a look the main part. Just to make sure, that no other timer is set, I let my variable "activ" get cleared by the function "clearTimeout".
The next part is about "how to restart the counter?". Here I am using the function "setTimeout", which needs a function and specified number of milliseconds to work. After the time runs out, the function will call "Show()".
And this will do the trick: within "Show()" I am switching the pages, finally.

To keep it simple, I'm just allowing 4 items in the array "addresses". The first step is to get a random number. For that, I'm using "Math.floor(Math.random()*length)". "Floor" rounds a number downwards to the nearest integer, which is needed for the array. "Random" will provide a number between 0 and 1. To get a number between 1 and 4 I have to multiply the result of "random" with the length of my array, which is 4.

Now we got our random number "i". But what to do with it?
Set a new address in the address bar with "document.location = addresses[i];". The second part will pick the address from the array, the first part with write this part in the address bar.

Now we are done. The pages will automatically switch every couple of minutes.

Monday, February 7, 2011

Getting started.

So...
finally I got a new blog. The first one for 5 years i believe.
Topics will bei just a lot of IT stuff. Especially everything that has to do with SharePoint.