Monday, April 16, 2012

SharePoint 2010 Table of Contents web part using javascript

One of the things I love about SharePoint is the ability to quickly create solutions utilizing the html web part or the content editor web part, lately I have been using the html web part as it is just a bit friendlier to use when adding client side code to handle tasks.

Today I have been trying to find an easy way to list all the sub sites in order to create a Table of Contents for our users, and while there are several ways you can do this without having to use code the Tree view and the actual Table of Contents web parts just were not meeting my needs, so a little javascript magic to the rescue!

Add a html web part to your page and then click the edit web part
Click the source editor button in the properties dialog box on the right
and paste in this script:


This script will loop through your sub sites and display a list of sites, I took it one step further and made each item a link that will take you to the site listed.

Tuesday, April 3, 2012

Powershell error when creating a new SharePoint Site

I ran into another odd problem with my SharePoint 2010 deployment yesterday.  I was trying to create a new site using the New-SPWeb PowerShell command and I kept getting the following error message:

PS C:\Users\rsmw> new-spweb http://sharepoint.local/newspweb
New-SPWeb : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At line:1 char:10 + new-spweb <<<<  http://sp2010.mps.k12.mi.us/warrensm2
 + CategoryInfo          : InvalidData:
(Microsoft.Share....SPCmdletNewWeb:SPCmdletNewWeb) [New-SPWeb],
UnauthorizedAccessException
 + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletNewWeb
 
The account I was logged in with was a farm administrator and I could create sites through the web interface.   Apparently, I needed to add the farm administrator account to the Owners group of the parent site in order to create a new site. After that, all was good to go.

Sunday, April 1, 2012

Using PowerShell to set SharePoint 2010 MasterPage Recursively

During a recent development project to create a custom branded MasterPage for our 2010 portal, the page I had created had an EventReceiver that set the MasterPage to my custom MasterPage, however I forgot to enclose one of my vars with a semi colon and the page deployed but would not render, I kept getting a SharePoint error saying File not found!!! Even after retracting the solution with Visual Studio I kept getting the same error. I needed some way to reset the MasterPage to v4.master, enter PowerShell, my favorite way to work with admin task. Thanks to Todd Lindt's quick post found here:
http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=226

The master page setting is scoped at the web level, so the first thing I did was use Get-SPWeb to get a variable for the web I want to change. There are two properties that control the master page settings; MasterUrl and CustomMasterUrl. The former controls the master page used to render the System pages (the ones that start with /_layouts) and the latter controls the master page used to render the content pages.


To alter those settings for a publishing site at http://sharepoint/, use the following PowerShell script:

$web = Get-SPWeb http://sharepointurl/
$web.CustomMasterUrl = "/_catalogs/masterpage/customMasterPage.master"
$web.MasterUrl = "/_catalogs/masterpage/customMasterPage.master"
$web.Update()
This changes the master page for both settings and content to a customMasterPage.master. You can also set it to the default v4.master if you just need to reset it to the default masterpage. Since we're doing this with PowerShell it's easy to loop through a group of webs and set their master pages to whatever you like

Friday, January 22, 2010

jQuery - How screen scrape a table from another web page

Lately at work we have needed to add additional content to our SharePoint Portal, one of the ways to implement quick and easy functionality is to use a Content Editor Webpart and some jquery. Everyday I find new and interesting ways to utilize this amazing javascript library to automate and execute redundant and boring tasks, thereby making end users lives easier and making myself into something of hometown hero.

This post will demonstrate using jquery to retrieve an html table from a weather website and pull it into your portal page. You will need to have the small jquery.js library uploaded into a shared top level site, there is nothing to install, just download the jquery library file and put it into a document library, as you will need to reference the path to the file when using jquery on your pages.

Also create a text file and add the following script to it,



save it as a .txt file and upload it to the same document library your jquery.js file is in.

Now go to the page you want the scraped item to show up on and put your page into Edit Mode and insert a Content Editor Webpart, once it is on the page then you will need to edit the properties and have it pointed to our text file that contains this script, this is way faster to troubleshoot and debug, no more having to save the page to see your changes, then put it back into edit mode to adjust the script.
This is so simple and yet so powerful! First I am looking to extract a table from the target webpage, so we use the html tag #table, (you could target any html element), in this case the target web page table tags does not contain IDs which would make it extremely easy to find the specific table I need, so I need to use the nth-child() to grab the table I want. You may have to experiment to find which table you want, just keep changing the number. Once you have your html element you can then use jquery to dress it up anyway you want or perform additional functions.

Monday, November 23, 2009

SP2010 PDF Icon - Quick Install for x64 bit systems

This script is updated to install the PDF Icon and re-set IIS for x64 bit systems. It backs up the original file DOCICON.XML to DOCION.old in case you need to recover it. PDFIcon v4 You will still need to download the iFilter for indexing/searching PDF files Adobe PDF iFilter 9 for 64-bit platforms

Tuesday, May 19, 2009

SharePoint 2003 - Renaming a Sub Site

A little issue I ran into this past week was that we needed to rename a Subsite on our old 2003 Portal that is still hanging around. Initially I thought I could use the Alternative Access Mappings but this only works for a FQDN, not for individual subsites, for those you have to use SharePoint Designer.

Open the site you need to rename in SharePoint Designer, then select 'Site > Site Settings', you can change the 'Web name'. This will change the URL and updates all appropriate links. Any links that may have been hard coded into say a Link webpart will have to be updated manually, although your users will let you know soon enough if you missed anything! ;)

Also all checked out documents need to be checked in otherwise you will get an error saying Document name is checked out, luckily it gives you the URL to find the document and check it back in.

Wednesday, May 6, 2009

SharePoint 2007 List Workflow - Send an email to users when an item is changed

I have been focused lately on cracking open the SharePoint 2007 Workflow engine to automate the process of routine tasks. This week I have been working on our help desk list that tracks the issues we have with our portal. The basic flow is that a knowledge worker can browse to our help desk site and submit a ticket for issues or suggest feature improvements.This is also a great way to start building a knowledge base for users to search for answers, or for new techs that come in and get stuck manning the phone lines. We have several applications that we have built that need to babied, so this has helped us reduce the amount of phone calls we get, now instead we just deal with the issues via our Help Desk List and then use email, with an occasional call to fix the problems. On to the good stuff...One thing we wanted to do was to have a way for the list to automatically display additional user information with out the user having to enter in the details, such as email address and phone number. Since we use Active Directory it makes sense to just grab the data based off the users name that is captured when they fill out a ticket and drop the information right into the list via a workflow.In our case we simply add 2 additional Person or Group fields to our list, user email and user telephone number, both of which we uncheck the Add to default view, so when the user initially fills out the ticket they do not see those fields and try and add data to them. The columns need to auto populate the data, so in this column we set the field to Work e-mail, so that when the Workflow runs it will put the users email address into the view of the list. Keep in mind when you are editing the list item you will see the users name in this field, like so: But when you look at the item in the list you will see the data like so: It is helpful to have this information so that I don't have to look it up every time I need to contact someone about an issue I am working on. This information is populated every time a new item in the list is created, which makes perfect sense. To do this you need to open SharePoint designer, which is now a free download.Once you open SPD and you navigate to the site where your list resides, Click File > New > Workflow. This will start the Workflow Designer. You will now need to configure a few settings such as the name of the workflow and start options. You will want the workflow to start Automatically when a new item is created. Since you need this workflow to start when a new item is created you will not need to add any Conditions. We will select the Update item from the Actions button and then select the list you want to work with, in this case it is Tickets. Now you can click on the Tickets link and a new window will pop open Click the Add button and select the field you want to populate, in this case it will be Contact Email Now click the fx button so we can use one of the fields that contains the users data as the look up source. In this case our list uses a column called Responsible Contact, the reason we did this is because sometimes users will open a ticket and assign it to someone else, like for example when someone bypasses the ticket system and calls me directly I want to be able to create a ticket and make them the responsible contact, also if they are having an issue getting on the portal they may not be able to use the help desk site to submit a ticket, you could also use the Created by field, but that would be too limiting for our needs. Click Ok 2x and you should be good to go. You can click Finish and now go back to your list and create a new item. Once the item in the list has been created you will be taken back to the main list and the additional information has not populated, you just need to refresh the page to see it, I am not sure why it does this, unless it has something to do with caching of the page. You can use this process to do all kinds of cool things that would ordinarliy take a few extra mouse clicks through out your day. The next step in this process is to send an email to the Responsible Contact whenever the person working on the ticket updates the information in the ticket. This feedback was a request by the users so they would not have to constantly go into the list to see what was happening with the issue. We needed to capture the users email address in order to do this with out having to code a solution in Visual Studio. So all the previous steps we did were in anticipation for this next step. We also have to use 2 seperate workflows in order to make this work correctly, otherwise you will get an error trying to combine an update and fire off the email in the same workflow, beleive me I spent a whole day trying to make it work with no luck! ;) You should still have SPD open, so again click on File>New > Workflow to start the Workflow Designer. Name your workflow something clever, select the list you want to work with, I will use the Tickets List again, and select the Automatically start this workflow whenever an item is changed. Click Next, this time we are going to set a condition so that the workflow will know to send an email when the Case Status column has been updated, this is a business rule for us, when we take control of a ticket in the queue we are supposed to update this drop down with a new status. Click the Conditions button and select Compare Tickets field Once that is done you will see Here you will click on field and select the Case Status and then click on equals and change it to "does not contain" click on value and I will select 1 -New, which is the default status for all tickets when they get created. Remember we only want to send an email when the Case Status changes from 1-New. Now that you have set the Condition its time to set the Action, which will be to Send an Email. Click the "this message" text to open the message editor window.Here you are seeing the message I composed with values selected from the list that will give the user some basic information such as the ticket name, the status of the ticket, and the comments that the tech working on the ticket wrote. We also include a link to the ticket so that the user can take a look or provide feedback or requested information. A note on the link back to the ticket, is that you will have to write out the url mostly by hand. For some reason Microsoft apparently did not think that users would need to use a workflow with lists in the same way we do with document libraries. For example any time a change is made to a document in a doc library you can select the user or group of users to be notified with one of the built in workflows that come out of the box, however for a list this is just not possible without creating a custom workflow like we just did. Wrapping this up you can send an email to the Responsible Contact now by clicking on the Address book icon in the To: line and select the Workflow Lookup, click the Add button select the Contact Email in the field drop down. This is the so far been the easiest way to automate this task. And yes I am well aware of the option to use Alerts to do this same type of task, however you can not expect the user to set an alerts.