Category: Top Posts

jQuery Random Quote Viewer

While doing some housekeeping recently on my personal site I was tinkering around with a pre-jQuery ajax enabled web part I had written to display random quotes from a SharePoint list on the site. The code was pretty ugly so I decided to adapt the web service call to use jQuery instead in line with the similar functions displays I’ve been deploying lately.

I thought I might take the time to share it as well since jQuery is still a hot topic.

Here is what the display looks like.jQuery Random Quote Viewer

The SharePoint list is a basic list with a column for the Quote and a column for the Author.

The code is currently hosted in a Content Editor Web Part (CEWP) and is pretty simple stuff. If you are going to use this, just be sure to put in the name or GUID of the list and the URL to the site’s list web service. Here is what it looks like:



$(document).ready(function() {
var URL = ""; // URL ex. http://mycompany/sites/sub-site/_vti_bin/lists.asmx
var listName = ""; // List Name or GUID

var soapEnv = "


" + listName + "





";

$.ajax({
url: URL,
beforeSend: function(xhr) {
xhr.setRequestHeader("SOAPAction",
"http://schemas.microsoft.com/sharepoint/soap/GetListItems");
},
type: "POST",
dataType: "xml",
data: soapEnv,
complete: DisplayQuote,
error: function(xhr) { $("#errorContainer").html('Error: ' + xhr.status + ' ' + xhr.statusText); },
contentType: "text/xml; charset="utf-8""
});
});

function DisplayQuote(xData, status)
{
var Output;
var WikiString = "http://en.wikipedia.org/wiki/Special:Search?fulltext=Search&search;="
var xmlDoc = xData.responseXML;
var ListItems = xmlDoc.getElementsByTagName("z:row") || xmlDoc.getElementsByTagNameNS("*","row");
var SelectedItem = Math.floor(Math.random()* ListItems.length);
var Quote = ListItems[SelectedItem].getAttribute("ows_Quote");
var Author = ListItems[SelectedItem].getAttribute("ows_Author0");
Output = "" + Quote + " - " + "" + Author + "";
$("#quoteContainer").html(Output);
}

While this is simple code, it can be applied to so many different things.  You can use it to generate a slide show, show random images, etc. 

The source files are available here:

 

Related Links

Using jQuery to Update an Item Without A Form

I have been investigating jQuery for about six months now. There are some great examples of it out on the Internet through sources like Paul Grenier’s “jQuery for Everyone” series on End User SharePoint as well as Jan Tielen’s blog. Most of the examples I have seen relate to using it to change style and formatting of standard content. It is definitely good at that with its rich selector formatting.

In a recent project I hit an interesting snag that was ultimately solved by using jQuery. I had an interesting project requirement for a SharePoint workflow solution where the users wanted to be able to cancel a request by simply clicking a button from a list of open requests.

Initially I didn’t expect this to be much of an issue since I had done some DataForms in the past. I ended up finding two limitations to this process though; overriding default values is not easy because the fields are databound, and any changes to any rows are saved on submit of the form. This means that if you do override the field you are looking to change, every row shown in the form would change not just the individual row for the button clicked.

My next thought brought me to building a custom web part to do this. In fact this is something I have done many times in the past for somewhat similar requests. This was not a good option though since the rest of the display could need to change frequently and really should be more dynamic and configurable. In the end the cost to maintain this would be too high.

I decided jQuery was the best solution for this particular project. It gave me the ability to keep the display as a DataView which is easily configurable, and call a script on the page that can perform updates via a jQuery to SharePoint UpdateListItems web service call.

Button placed in the XSLT of a DataView

Script placed in a Content Editor Web Part

In the end, the code was very simple yet effective. As I get a handle on all of the capabilities, I see it becoming more and more central to my development toolkit.

SharePoint Quota Management

SharePoint ships with a decent set of Quota Management tools. Many of the people I talk to are not familiar with the tools because they do not believe they need quotas. I think the tools offer valuable information that can be used to help maintain a well run farm even if strict quota management is not needed. Without the tools, you increase the likelihood of excess content being stored which leads to longer backup and recovery times and additional storage needs.

If sites really do not need to be limited, I would advocate setting the quota limits very high as opposed to not enabling them or turning them off.

Storage Space Allocation Report
The tools are available to Site Collection Administrators from the Site Settings page at the root of the Site Collection.

The tools will list out all of the content in the Site Collection. You can review Document Libraries, Documents, Lists, and the Recycle Bin.

Document Libraries – I find it helpful to know which libraries have the most content. By reviewing this list you can get an idea of which Document Libraries to target when reviewing the information architecture and taxonomy issues. This may also provide the information needed to make decisions on restructuring sites and site collections so that they are smaller and nimbler helping to reduce recovery time during disaster recovery.

Documents – It can also be informative to know how big the bigger documents are. This report will actually roll in prior versions as well so if there are a large number of versions you can review and clean up as needed. In the prior version of SharePoint it was not possible to set a maximum number of versions to save so I used this to review and manage prior versions. I had one case where there were some financial spreadsheets with over 100 versions at 75mb each. That is just wasted space unless there is a real business need.

Lists – List size can be very difficult to figure out without this tool. The number of records is important to know, but if there are attachments the list size can grow very quickly. This report will detail both the number of items, as well as the storage space consumed.

Recycle Bin – It will also report out what is in the recycle bin. There is nothing too exciting here.

How to Manage Quota Templates
The quota templates are available in Central Administration under Application Management, Quota Templates.

If you do not really want to manage quotas you can set this to a large value. If you have a charge back system in place where groups pay for the storage they use, try to identify a few different standard categories and assign a warning and max level. Here are some categories that I have used before.

• Personal Sites
• Personal Sites – Executive
• Medium Document Storage
• Heavy Document Storage
• Light Collaboration
• Medium Collaboration
• Heavy Collaboration

How to Enable Quota Management
The screen to enable quota management on a site collection is available in Central Administration under Application Management, Site Collection Quotas and Locks.

Note: If a site goes over its configured quota it will be set to locked. Even if you adjust the quota size you will still need to remove the lock.

Supporting Multiple Active Directory Domains

In many environments there is more than one Active Directory forest with users that need access to the SharePoint farm. Setting up support for users on multiple domains is pretty easy and can provide new collaborative features for users throughout the extended organization.

Trust Relationship
The only prerequisite is that there has to be a trust relationship between the forests. Users from the other domain(s) will need to be able to authenticate and access resources on the host domain.

If that trust is not in place, here is a good resource: Support for Cross-forest deployments

Setting up the Import
The Profile import settings are in the Shared Service Provider’s User Profile section. Setting up the primary domain, the domain the server is on, is pretty straight forward and the default settings should be fine.

To setup an import for additional domains click on the “View import connections” link from the main User Profiles and Properties page followed by the Add Connection item in the toolbar. Fill in the domain information and click the Auto Fill Root Search Base button. If the SharePoint Administration account does not have access to read from the target domain you will need to supply an account to read the directory.

People Picker Control
If there is a one way trust, or there are duplicate accounts (display names) on different domains it may be a good idea to set some additional properties. In the article Select user from multiple forest domains it provides a path to specify which forests to search, and allows the passing of credentials if the SharePoint Administration account does not have the required privileges.

Summary
The platform does a good job of supporting cross domain collaboration, and it is a lot easier to setup than many enterprise systems. In one environment I had to support over thirty domains so the information included above really came in handy.

Resolving the MySite File Exists Error

I have seen this error come up a few times, and reported frequently on the MSDN/TechNet Forums. Once the problem is understood, it is fairly easy to correct.

There are a few different pieces that come into play when a user clicks on the My Site link at the top of a MOSS page. The user goes through a centralized MySite.aspx page that acts as a redirect. A check is done to see if the user already has a My Site specified in their profile. If there is a site specified it sends them to the site, if the site is not specified it sends them through the site creation process.

Error
On a couple of occasions I have seen the following error:

The file exists. (Exception from HRESULT: 0x80070050)

Troubleshoot issues with Windows SharePoint Services.

This happens because the user’s profile does not contain a valid path in the Personal site field. The user is then pushed into the site provisioning process, but since the site paths have to be unique, the process is unable to create a new site.

For some reason the profile field was reset or corrupted leaving it blank or filled with something like an error code or invalid statement.

Resolution
To resolve this issue, you want to first validate the path to the user’s site. The path will vary depending on your setup and naming conventions, but it should be something like http://servername/personal/juser

Once you know what the valid path is, update the Personal site property to include the valid path. Ex. “/personal/juser”

To update the user’s profile:

  • Navigate to the Shared Service Provider
  • Click the User profiles and properties link
  • Click the View user profile link
  • Search for the user’s profile
  • Click the Edit option in the item’s menu
  • Update the Personal site property
  • Click the Save and close option in the toolbar

What causes the error?
On a few occasions the cause could not be determined. Since it was easy to fix we didn’t spend a whole lot of time looking into the cause. The majority of the instances happened after an Active Directory migration where the user’s profile was migrated incorrectly.

When going through an account migration either through Active Directory, or in switching to something like Forms Based Authentication (FBA), make sure you migrate the user profiles using Migrate User. Additional information can be found on that topic at the blog post titled SharePoint AD Migrations: Users and Servers.

SharePoint Active Directory Migrations: Users and Servers

I have been hearing more and more questions recently about Active Directory migrations with relation to SharePoint deployments. It could be from some organizational changes, or because business managers just like to keep people busy.

When I had to go through this process during the summer of 2008 I found much less information that I expected so I had to work through some of the problems myself. Here is the result of what I found. Hopefully it can assist other organizations in the process.

I have broken everything into five steps; Prep, Server Move, Service Updates, Migrating User Accounts, and Post-Migration Validation.

SharePoint Supports Multiple Domains
One thing I want to point out is that SharePoint works great in environments with multiple domains. The only prerequisite is that proper domain trust is in place to support authenticating users across the domains.

If the users will be migrated slowly over a period of time services should go uninterrupted. It is possible to keep the servers and services running on the old domain until all users are migrated, or move the servers and services early on and then run the user migrations in batches over time.

Preparation
Before any major system changes it is always a good idea to perform and validate a fully system and content backup. It is also essential to ensure that you have a non-domain account available on the server that you can use to access the server after it has been removed from the domain.

I would also make sure that all of your site profiles are currently up to date. To do this run the following command:

stsadm -o sync -excludewebapps {Web applications} -synctiming {schedule} -sweeptiming {schedule} -listolddatabases {days} -deleteolddatabases {days}

TechNet Documentation for STSADM –o sync: http://technet.microsoft.com/en-us/library/cc263196.aspx

Server Migration
Migrating the server from the old domain to the new domain is handled through regular computer settings and is not SharePoint specific. If you do this manually, keep in mind that you will need an administrator account on the server after it is removed from the domain in order to join it to the new domain.

There are some good Active Directory migration tools from vendors like Quest software that can automate the move process. In addition to the remove and joining to the new domain it can migrate the user profiles and add in a list of domain users to the local Administrators group.

Update Services
Migrating the farm services is pretty quick and easy. There are commands in the stsadm tool that allow you to update all of the accounts used within the services and IIS application pools.

Run the commands and then reboot the servers so that all services load under their new identities.

The following MS Support link provides an overview and examples. http://support.microsoft.com/kb/934838

Migrate User Accounts

stsadm -o migrateuser -oldlogin {domainname} -newlogin {domainname} [-ignoresidhistory]

The ignoresidhistory input at the end is optional. The SID is a guid for that user account, and a reference to it is stored in the SharePoint profile. If the accounts were migrated correctly the SID history should be maintained.

By default the migrateuser command will validate that the oldlogin and newlogin have the same SID. For cases where the SID history was not maintained, you will receive an error about the SID not matching, and you will need to supply this input.

The validation is helpful in preventing incorrect account migrations where there are two users with the same username. This happens frequently with common names like Smith, Johnson, or Garcia.

The command needs to be run for each user you need to migrate. This can be done user by user, or in large batches. However you run it, make sure that you have access to the results so that you can review and correct the exceptions.

TechNet Documentation for STSADM –o MigrateUser: http://technet.microsoft.com/en-us/library/cc262141.aspx

Post-Migration Validation
After the services are moved, standard test cases apply. Make sure that the main site collections load, user permissions are maintained, and that search queries return accurate results.

If you run MOSS you will want to setup the profile import to the new domain. This will ensure that updates are pulled in over time.

You can use the profile lookup form in the Shared Service Provider to search for profiles on the old server. Use a Wildcard “*” after the domain name to pull back all users for a given domain.

If you want to look at the site collections and see how many accounts are on the old domain user can query the Content Databases. You will need to run the query against each Content DB.

Disclaimer: Accessing production databases even just to query may not be a good idea. Do this at your own risk.

select distinct tp_login, tp_email, tp_title
from {ContentDBName}.dbo.userinfo
where tp_login like ‘{Old Domain}%’ order by tp_login

%d bloggers like this: