Archive for June, 2008


What is Script.aculo.us?

Script.aculo.us gives developers a new way to code in JavaScript by providing new shortcut functions, new powerful objects including Form, Effect, Control and Ajax, and some custom widgets. It’s an add-on to the Prototype.js JavaScript library.

What is Prototype?

Prototype by itself is a very well thought out and implemented library of JavaScript methods that helps a great deal with creating rich, highly interactive, and dynamic web pages.

The focus of this article will be to get you started using these two frameworks in your SharePoint projects. It’s really simple to do, and the frameworks themselves are not that difficult to learn.

Let’s begin:

  1. Download the files from http://www.prototypejs.org/download and http://script.aculo.us/downloads. The prototypejs download is a single file. The Script.aculo.us download is a zip archive with several files included.
  2. Extract the Script.aculo.us files to your project directory where they can be referenced. Place the prototype file there as well. In my case, I was developing a custom application page within MOSS. I placed the files in that layouts folder where my custom application pages were located.
    1
    
    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\CustomApplicationPages\
  3. Inside your project files you only have to include 2 files. The prototype.js file and the scriptaculous.js file. The scriptaculous.js file will load all the other necessary js files for you. Within my custom application page, I added my script tags just after the main content placeholder as follows:
    1
    2
    3
    4
    5
    
    <asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
     
    <script src="prototype.js" type="text/javascript"></script>
     
    <script type="text/javascript" src="scriptaculous.js"></script>
  4. Now within my custom appliation pages, I can leverage the frameworks to make my pages do some cool things. An example of how to use it:
    1
    2
    3
    
    <div onclick="new Effect.Appear('nameHelp')">Appear</div>
     
    <div id="nameHelp" style='display:none;overflow: auto;'>Some content here.</div>

This example is just a small example of what you can do. Check out the Script.aculo.us and Prototype documentation for an idea of what else is possible. If you’re having any trouble getting this going, just drop me a note.

During a recent migration from SPS2003 to MOSS, the question came up of how to redirect users to old content while the team site was still being cut over.

Scenario: I have SPS2003 running on http://oldserver and MOSS running on http://newserver.

What I needed to do was create place holders for certain sites so that when a user hit the site on the new server (http://newserver/SiteDirectory/demosite), they would be redirected back to the old content (http://oldserver/sites/demosite).

This is how I accomplished this:

  1. Setup a new team sites using the publishing site template. The key thing to note here is that you need to be able to create pages, so if you’re not using a publishing site template, then the published features need to be turned on.
  2. Within each team site, a new page was created using the (Redirect Page) Redirect Page page layout.
  3. The url to route to was configured in the redirect page.
  4. Within Site Settings, under Look and Feel, Welcome page, the new redirect page was selected.

That’s pretty much it. The next time I land on this site, it will redirect within a few seconds. I did a bit of research on this prior to implementing this and found a great article written by Todd Klindt.

In his article, he describes the various options for redirects available within SharePoint. I attempted the content editor option first but I found one key distrinction between that and the redirect page option.

The redirect page is smart enough to recognize when you are a site owner or an administrator and will give you some time before redirecting so that you’re able to administer the site. The content editor solution will redirect regardless of who you are and what permissions you have, thus making it difficult to access the Site Settings before the redirect occurs.

That’s it, hope that helps some people. I welcome all feedback.

SPWeb.SiteUsers vs SPWeb.Users

Update: I recently ran into this issue again and discovered that there is in fact a way to ensure that the user exists before creating the user object — the EnsureUser method of the SPWeb class. According to MSDN this method “Checks whether the specified login name belongs to a valid user of the Web site, and if the login name does not already exist, adds it to the Web site.” Check it out here. I tried this and it seems to resolve my issue. If the user is not a member of the web site, this method will add it which is effectively what I needed it to do.

Please note that you’ll need to set the AllowUnsafeUpdates property to true in order for the EnsureUser method to do it’s thing.

When trying to use SPWeb.Users to find a particular user in a site, I was receiving a “User cannot be found” error within the site that my method was being called from. I took a look at the site permissions and discovered that the user account I was attempting to add did not actually exist as a member of that site. At first glance, I didn’t actually think that this would be a problem, but apparently there is a key disctinction between the various SPWeb methods.

If I added the user to the site manually, the SPWeb.Users call worked. Any users automatically added to the site upon creation, will not be found with a SPWeb.Users call. This is an important disctinction.

My next attempt was to use SPWeb.SiteUsers which was only successful if the user existed at the site collection level. However, if the user was not a member of any group at the site collection level, my method would still fail with a “User cannot be found” error.

Alternatively, I might be able to leverage the user profile database to get a list of all possible users to choose from but I haven’t done any experimenting with this yet. If anyone has any additional information or feedback on this, please drop me a note.

Windows SharePoint Services 3.0 SDK

SPWeb.AllUsers – Gets the collection of user objects that represents all users who are either members of the site or who have browsed to the site as authenticated members of a domain group in the site.

SPWeb.SiteUsers – Gets the collection of all users that belong to the site collection.

SPWeb.Users – Gets the collection of user objects that are explicitly assigned permissions on the Web site.

I recently ran into an issue where I needed to use SharePoint Designer to add a workflow to a list within a site. However, if I opened the site within SharePoint Designer, it would load in Contributor mode thus preventing me from creating any workflows. Here is my scenario:

  1. Backed up a site collection from a server on domainA
  2. Restored it to a separate server on domainB
  3. Made my user account a site collection administrator
  4. Opened up the site in Sharepoint Designer, and only had Contributor mode access. This access was insufficient because I was trying to create a workflow.

Solution:

The issue is related to the fact that I did a backup and restore from one environment to another, within different domains. Making myself a site collection administrator was not enough. There were residual accounts within my restored site collection that no longer applied. What I noticed is that when creating a new site collection, my account is automatically added to the site owners group for that site; however, when doing a restore, this doesn’t seem to happen.

It seems that sharepoint designer actually looks at the site owner group permissions, so i simply added my account to the site owners group, and my problem was solved. The next time I opened SharePoint Designer, I was no longer in Contributor mode.

So the key thing to note here is make sure your account is a member of the site owners group.

Powered by WordPress | Theme: Motion by 85ideas.