fredag den 7. maj 2010

Pop Up New Window Using the Out-of-the-box Links List

SharePoint "links lists" are very handy. The only problem is that out-of-the-box, the links take over the browser window. While desirable for some navigation tasks, it is not always optimal.

Sometimes I use a Content Editor Web Part to make custom links, but these are not permission sensitive the way SharePoin Lists can be.

There is a 3rd party web part add-on called "Windows Links" for WSS3/MOSS2007 (see this article) that works just fine, but it requires an installation of the web part. This can (and probably will) cause issues during an upgrade to the next version of SharePoint.

The basic idea is that Link List is added to a Web Part Zone on a site page or web part page. Then a Content Editor Web Part is added (anywhere) onto the same page.

The code is entered into a Content Editor Web Part using the "Source Editor" (not the Rich Text Editor), as pictured below.

Copy/Paste code below:

<script language="JavaScript">
//add an entry to the _spBodyOnLoadFunctionNames array
//so that our function will run on the pageLoad event
_spBodyOnLoadFunctionNames.push("rewriteLinks");
function rewriteLinks() {
//create an array to store all the anchor elements in the page
var anchors = document.getElementsByTagName("a");
//loop through the array
for (var x=0; x<anchors.length; x++) {
//does this anchor element contain #openinnewwindow?
if (anchors[x].outerHTML.indexOf('#openinnewwindow')>0)
{
//store the HTML for this anchor element
oldText = anchors[x].outerHTML;
//rewrite the URL to remove our test text and add a target instead
newText = oldText.replace(/#openinnewwindow/,'" target="_blank');
//write the HTML back to the browser
anchors[x].outerHTML = newText;
}
}
}
</script>

The Content Editor Web Part can be hidden if desired (look in the "Layout" section of the web part options).

And finally, when creating links in the Links List, add #openinnewwindow on the end of each link that you would like to open in a new window.


 

torsdag den 28. januar 2010

Hvordan man fjerner overskrifter i grupperet visning af lister

Man starter med en liste som er grupperet:

Hvis man så ønsker at fjerne overskrifterne:

Kan kan via et javascript fjerne teksterne:

1. Tilføj en webdel til inholdsredigering (CEWP)

2. Åben i kildeeditor og indsæt koden:

Kode:

<script type="text/javascript" language="javascript">

_spBodyOnLoadFunctionNames.push("HideHeaders");

function HideHeaders()

{

var elements = getElementsByClassName(document, "td", "ms-gb");

var elem;

for(var i=0;i<elements.length;i++)

{

elem = elements[i];

elem.childNodes[3].style.display = "none";

elem.childNodes[4].nodeValue = elem.childNodes[4].nodeValue.replace(':', '');

elem.childNodes[5].style.display = "none";

}

elements = getElementsByClassName(document, "td", "ms-gb2");

for(var i=0;i<elements.length;i++)

{

elem = elements[i];

elem.childNodes[3].style.display = "none";

elem.childNodes[4].nodeValue = elem.childNodes[4].nodeValue.replace(':', '');

}

elements = getElementsByClassName(document, "tr", "ms-viewheadertr");

for(var i=0;i<elements.length;i++)

{

elem = elements[i];

elem.style.display = "none";

}

}

function getElementsByClassName(oElm, strTagName, strClassName){

var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);

var arrReturnElements = new Array();

strClassName = strClassName.replace(/\-/g, "\\-");

var oRegExp = new RegExp("(^\\s)" + strClassName + "(\\s$)");

var oElement;

for(var i=0; i<arrElements.length; i++){

oElement = arrElements[i];

if(oRegExp.test(oElement.className)){

arrReturnElements.push(oElement);

}

}

return (arrReturnElements)

}

</script>


Resultat:



Hvis man så vil ændre skriftstørrelserne kan man tilføje følgende kode:

<style>

.ms-gb

{

font-size: 9pt;

color: black;

border-style: none;

}

.ms-gb2

{

font-size: 10pt;

color: red;

}

</style>


Hvis man så vil af med linierne i mellem kan man tilføje følgende kode:

.ms-vh-group

{

display: none;

}

Lav en Sharpoint 2010 (64bit) på en 32 bit maskine

Her en god artikel om hvordan man laver en sharepoint 2010 (som kun kan fås i en 64 bit udgave) på en 32 bit maskine.

http://sharemyp0int.blogspot.com/2010/01/create-sharepoint-2010-virtual-machine.html

fredag den 14. august 2009

Send mail i PowerShell

#####################################
function SendMail([string]$TextToSend)
{
$filename = "filename.txt"
$smtpServer = "SmtpServerName"

$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($filename)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)

[string]$tempFrom = $env:computername + ' <' + $env:computername + "@" + $env:userdomain + ".COM>"
$tempFrom $msg.From = $tempFrom
$msg.To.Add("sendto@domain.com")
$msg.Subject = "Subject"
$msg.Body = $TextToSend$msg.Attachments.Add($att)

$smtp.Send($msg)
$msg.dispose()
}
#####################################

onsdag den 5. august 2009

Sharepoint 2010 Links

Redirect SharePoint Site to New Location

1. Add a Content Editor Web Part to the Main Page of the site.
2. Modify the Web Part and click on Source Editor.
3. Paste in the following code while changing the URLs to match your target.

<HTML>
<HEAD>
<SCRIPT language="JavaScript">
<!--
function redirectsp()
{
top.location="http://sharepoint";
}
if (top.frames.length==0)
{
setTimeout('redirectsp()',0);
}
//-->
</SCRIPT>
</HEAD>
<body>
Redirecting you to the new location. If you are not redirected, click <a href="http://sharepoint">HERE.</a>
</body>
</html>

4. I set the redirect time to 0, but you can set it higher if you like. 1 sec = 1000, 2 sec = 2000, etc.
5. Save the code changes.

The fun part of this solution is the fact that the code tries to load no matter what view you are in (i.e. Standard view, Edit Page, etc). So, if you have to make changes to the code you have to let the page load but then time a press of the ESC key to keep the Javascript from loading each
time.

tirsdag den 26. maj 2009