Archive | July, 2012

How I am using a Delegate control, code in a Document library, and jQuery to customize SharePoint 2010

In this post, I showed how to put a delegate control at the top over every page, and in the control add the links to the jQuery libraries. This is nothing new, there are many articles that show how to do this. I took this a step further and I included code to do the following:

  1. Determine the current page’s relative URL (where the delegate control is running) and put that value in a Variable
  2. Take that variable and change the relative URL’s forward slashes (“/”) to underscores (“_”), and change “.aspx” to “.txt”
  3. Look for a file in a document library with a name that matches the variable created above and insert it’s contents into the additional page header

For example if  I am browsing to http://sharepoint.company.com/Lists/Announcements/AllItems.aspx, and there is a file in the desiganted Document library named “_lists_announcements_allitems.txt” then it’s contentens will show up in the addition page header.

Some of the benefits I have found with my methods

  1. All client side code is kept in one place, and you can easly figure out which file is being used on each page
  2. The Document Library can have versioning, so you can rollback changes
  3. Linked CEWP can be kept in the same place
  4. It is easy to edit text, js and css files in SharePoint Designer, rather than in CEWP
  5. Now it is a snap to chop up a NewForum.aspx via jQuery
  6. It is easy to extend the code so that a file is included across all pages, making it easy to add a new js library to the entire site

Here is the code I am using in the Delegate Control (ascx)

string CurrentSiteRelativeURL = CurrentUrl.ToLower().Replace(CurrentWeb.Url.ToLower(), "");
string CustomFileName = CurrentSiteRelativeURL.Replace("/", "_");
string PageSpecificHeaderIncludes = CurrentWeb.Url + "/DocumentLibraryWithCodeInIt/" + CustomFileName.Replace(".aspx", ".txt");

Response.Write("<!--PageSpecificHeaderIncludes:" + PageSpecificHeaderIncludes + "-->");
    if (CurrentWeb.GetFile(PageSpecificHeaderIncludes).Exists == true)
    {
        SPFile tempFile = CurrentWeb.GetFile(PageSpecificHeaderIncludes);
        StreamReader reader = new StreamReader(tempFile.OpenBinaryStream());
        string myText = reader.ReadToEnd();
        reader.Close();
        Response.Write(myText);
    }

Anyone else doing anything like this? Thoughts?

jQuery to hide a column

I wanted to hide a column and I found this simple way to do that in jQuery. Can’t find where I originally came across it. Sorry if you figured it out first.

$('th:nth-child(5),td:nth-child(5),th:nth-child(6),td:nth-child(6)').hide()

This hides the 5th and 6th columns. I am going to use this in a SharePoint list where I want to hide the column and put the contents in a jQuery dialog box. More on that in a bit (I hope).

Update: found my source for this

Problems with TweetDeck and Enterprise Deployment (SCCM)

Been working with @xrobx99 on this one. We had a request for TweetDeck to be installed on a couple of user’s machines. We feared that word would get out and everyone would have to have it. So we have been looking into deploying TweeDeck silently through SCCM. Using my SCCM PowerShell install script (which is basically just a wrapper for the msi commands) we have observerd the following issues below:

When run silently with the command:  msiexec /i TweetDeck.msi /q /norestart /l c:\Temp\TweetDeck.log

  • Short-cuts don’t get created
  • TweetDeck does not show up in Add Remove programs

Other Non-enterprise ready issues that we have observed:

  • No way to know the current version number without installing first (shouldn’t it be in the MSI properties?)
  • Web site does not show the current version number
  • Is there a way to NOT check/prompt for update on close? This is annoying for non-administrators (they get a UAC prompt)
  • Twitter’s registry entry in HKCU\Software is not with a capitol “T” (I know, weak, but that kind of stuff drives me crazy)

It is entirely possible that I am doing something wrong, but those are my findings.

UPDATE I realized that I can use the ALLUSERS=1 parameter and the program will be installed for all users, then the Icons and Add remove programs will be correct. Maybe the packagers need to include ALLUSERS=1 in their packaging software? Updated install string:

msiexec /i TweetDeck.msi ALLUSERS=1 /q /norestart /l c:\Temp\TweetDeck.log

My Debian/Raspberry Pi cheat sheet (translations from CentOS)

I have worked on Solaris and RedHat/CentOS (although Solaris was many years ago, so I  should just admit that I no longer know where anything is). I find Debian to be a different dialect than RedHat. This post is going to serve as my translation cheat sheet.

  1. I use the  bash complete string below with ssh and ping. It was not working under Debain. Turns out that the host names are hashed in the known_hosts files under Debian. I had to add “HashKnownHosts no” to my .ssh/config and then re-populate the known_hosts file.
    complete -W "$(sed -e 's/^  *//' -e '/^#/d' -e 's/[, ].*//' -e '/\[/d' ~/.ssh/known_hosts | sort -u)" ssh ping
    
  2. Debian on arm does not seem to have sysvconfig so I need to go into /etc/init.d/script name to start,stop,restart,status a service
  3. To stop a service from running at boot “update-rc.d -f smb remove” (chkconfig smb off)
  4. To start a service at boot “update-rc.d nfs defaults” (chkconfig nsf off)
  5. cat /etc/debian_version = cat /etc/redhat-release
  6. More to come

RSS feed for a vBulletin forum

I am constantly having to look this up. What is a vBulletin’s form’s rss feed?

http://www.myforum.com/external.php?type=rss&forumids=1

Obviously the admin has to enable it. Have not tested against all versions

 

Server ran out of space and not accepting connections after freeing up space

I was away on vacation, and a dev box ran out of space. Once I got back, I cleaned it up, rebooted and still could not connect to it. @xrobx99 noticed an IPSec message in the event logs:

The IPSec driver has entered Block mode. IPSec will discard all inbound and outbound TCP/IP network traffic that is not permitted by boot-time IPSec Policy exemptions.

We thought that was suspect as we weren’t using IPSec policies. It seems that our server ran out of space and the IPSec policy became corrupted.

I ran the command :

regsvr32 polstore.dll

This command rebuilds the local policy store. I rebooted and all was fine.

Hope that helps someone.

How to add custom JavaScript code to all SharePoint 2010 pages (DelegateControl)

As I said in this post, there are plenty of articles on how to do this. This is more of a note for myself, as I have to “re-learn” this every time I need to customize SharePoint.

There are 2 ways (that I know of) that you can add code to every page in SharePoint 2010, 1 by the AdditionalPageHead delegate control, or ,2 by Custom Action. This article is about #1 (see #2 here) using the AdditionalPageHead delegate control.

  • Start Visual Studio, and create a new Empty SharePoint Project (uncheck the Create Directory for Solution because you salways create the destination directory yourself)
  • Deploy as a Farm Solution (I have not figured what you can and can’t do with sandboxed solutions yet)
  • RightClick the Project and Add –> New item –> User Control –Name it. This will create a new folder named ControlTemplates and inside will be your User Control. Looks like this

  • Edit the new ascx file and add the code you want to put at the top of every page, for example:
<script type="text/javascript" src="/path/to/jquery.js"></script>
  • RightCLick the Project and select Add Empty Element and name it at the bottom
  • add the following to the elements.xml file. The final should look like this below:
  <Control Id="AdditionalPageHead"
          Sequence="90"
          ControlSrc="~/_CONTROLTEMPLATES/DelegateControl/DelegateControl.ascx" />

Package everything up and you will now see your reference to jQuery on the top of all pages.

Powered by WordPress. Designed by WooThemes