Important notice

Please note that this blog is discontinued here. All the posts are also coppied to my new blog at http://boris.gomiunik.net.
Important: Due to large amount of comment spam further commenting has been disabled here. If you wish to send me a comment, plase look up the same post on my new blog and leave comment there. Thanks!

7/23/2007

QueryString - get parameters from URL with JavaScript

SharePoint passes a lot of information between pages with the aid of URL parameters. If you pay attention to the URL while watching the EditForm of some list, you'll probably find the folloring url:

http://server/site/lists/listname/EditForm.aspx?ID=1&Source=http://server/site/lists/listname/Allitems.aspx

The part after the question mark is important, since it's passing 2 parameters: ID with value of 1 and Source with value of http://server/site/lists/listname/Allitems.aspx.

Using XSLT with SharePoint Designer you can also get these parameters with XSLT's QueryString. But outside of a SharePoint Data View you can get the value of URL's parameters with the following script:

function queryString(parameter) { 
  var loc = location.search.substring(1, location.search.length);
  var param_value = false;

  var params = loc.split("&");
  for (i=0; i<params.length;i++) {
      param_name = params[i].substring(0,params[i].indexOf('='));
      if (param_name == parameter) {
          param_value = params[i].substring(params[i].indexOf('=')+1)
      }
  }
  if (param_value) {
      return param_value;
  }
  else {
      return false;
//Here determine return if no parameter is found
  }
}

So if I had my page http://www.mysite.com/default.aspx?test=123

The queryString('test') would return value 123.

This function is useful also outside of SharePoint. One word of caution though: Internet Explorer tends to translate a bit the urls, so spaces become %20 and similar. This can be solved with a simple function to translate these values. More about that - next time :)

7/17/2007

Refferencing SharePoint form fields with JavaScript

Sometimes you need to refference SharePoint form fields for manipulation. I usually use JavaScript. With SharePoint 2.0 you can refference a form field with

document.getElementsByName(urn:schemas-microsoft-com:office:office#Field_Name)[0]

where Field_Name is the SharePoint name of the field (you can find it at the end of URL when viewing properties of the field under "Modify Settings and columns". For example if I'd need to change the value of a form field Title, I'd use the following code:

document.getElementsByName('urn:schemas-microsoft-com:office:office#Title')[0].value = 'Boris'

Thus changing the value to Boris.

The story gets a bit more complicated with SharePoint 3.0. The names of fields now also contain ID of the form, which is constantly changing. The previous case in one of our forms would be

document.getElementsByName('ctl00$m$g_740df035_0c04_4906_89d7_cb38429413df$ctl00$ctl04$ctl00$ctl00$ctl00$ctl04$ctl00$ctl00$TextField')[0].value = 'Boris'

The problem occurs with changing ID of the form so you can't (at least that I know of) refference the form field value by name alone.

The solution here is using form titles. I've prepared a small javascript to get the form field by its type and title.

function getField(fieldType,fieldTitle) {
    var docTags = document.getElementsByTagName(fieldType);
    for (var i=0; i < docTags.length; i++) {
        if (docTags[i].title == fieldTitle) {
            return docTags[i]
        }
    }
}

Using this script now you can change the value of a title field with

getField('input','Title').value = 'Boris'

Page File on the server too high? Alternative to IISRESET

I've already been explaining in my previous post about application pools how to save on page file by reusing application pools.

When you need to release page file size and memory consumption, you can run iisreset. This will kill each application pool for each site and therefore release the memory (untill the site is revisited).

Joel Oleson is describing an alternative way to release the application pool and cache that we don't need without the 7-seconds-long iisreset. Below quoting from Joel's blog:

cscript c:\windows\system32\iisapp.vbs /a "%SharePointAppPool%" /r

Where %SharePointDefaultAppPool% is the app pool you are wanting to cycle.

7/09/2007

Unable to create SharePoint list from Excel (import spreadsheet)

If you're trying to import spreadsheet to create a SharePoint list in SharePoint 3.0 you can receive some errors. This especially occurs if you're using Excel 2003.

Thanks to Matjaž from Portorož, there is a resolution to this problem: update office 2003 to at least SP2 and the problem will go away.

7/07/2007

Another great .flv flash video player

In one of my previous posts I've already explained how to publish your own video on web pages (still a bit difficult in SharePoint blog :( because it gets filtered out). I've come across another very good .flv flash video player. It's published under creative commons licence and it's free for non.commercial use. What I also like about it is

Below is a sample video..
 

7/05/2007

SharePoint 3 is bound to host headers

With the old SharePoint we were using host headers much more freely. When the site was extended, all you needed to do is add additional host headers in the Internet Information Services console.

With SharePoint 3 the story is a bit different. When you create a site with host header through SharePoint Central Administration, that site is bound to the host header you created it with. This might cause problems with intranets (for example internal domain is one and external is other). Below is one solution (that I confess, I still have to try out) that might solve this problem:

Modifying ports and host headers on SharePoint

I also use the following trick: When the site is created, I go to the IIS administration console and add the desired host headers. Usually this will redirect to the original host header. Example: site is created with www.piflar.com, I've added also host header piflar.com. So when I visit http://piflar.com it automatically redirects to www.piflar.com.

The problem might occur with intranet sites. Internal domain can be http://companyweb2 and external http://intranet.company.com:444. If you visit the second url and redirects you to companyweb2 naturally you won't be able to open the site.  

The solution can be that you add the default.aspx after the url. So if you visit http://intranet.company.com:444/default.aspx you won't get redirected and you can see the SharePoint.