• How I went about creating two related lists using JavaScript, Client Object Model and SharePoint 2010-Part1

    I was struggling with how I could create two lists in SharePoint  2010 that were related.

    Scenario: Let’s say that you want to have a list of meetings (we will call it MeetingsList), with each meeting having the potential of unlimited number of attendees. How can I do this in SharePoint? It is not possible to have Attendee-1 to Attendee-∞ (infinity) as fields in the MettingsList. I needed to move the attendees to their own list (we will call it AttendeeList). But how do I related the attendees to the meeting?

    My work around: The trick was that I needed to know the MeetingsList item’s ID before I created the related attendees. I could not figure a way to get that ID until after the MeetingsList item was saved. The work around that I came up with was that I would create the item when a person clicked the “new” button, and then redirect them to EDIT the newly created item. Then I could add an item to the AttendeeList with ID of the current item being edited in the MeetingsList. Hope that makes sense. Steps and code:

    • Create a list that contains the meeting specifics – MeetingsList
    • Create a second list that will contain the attendees – AttendeeList
    • Use my Delegate Control method to insert JavaScript (code kept in a document library) into  the top of any page as described here
    • Add the following to the top of the NewForm.aspx page:
    $(document).ready(function() {
    	ExecuteOrDelayUntilScriptLoaded(createListItem,"SP.js");
    });
    function createListItem() {
        var clientContext = SP.ClientContext.get_current();
        var oList = clientContext.get_web().get_lists().getByTitle('MeetingsList');
        var itemCreateInfo = new SP.ListItemCreationInformation();
        this.oListItem = oList.addItem(itemCreateInfo);
        oListItem.update();
        clientContext.load(oListItem);
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
        }
    
    function onQuerySucceeded() {
    window.location.href = "/Lists/MeetingsList/EditForm.aspx?ID="+ oListItem.get_id();
    }
    
    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }
    

    All this Client Object Model code does is create a new item in the MeetingList list, and then redirect the browser to edit that item. Now, on the EditForm.aspx page, I know the item ID of the item I am editing and I can use this ID to create a new related item in the AttendeeList. Next steps are in part 2.


  • Almost to 10,000 visits in a month!

    Using my fun Google Analyitics Bash Script

    July 9151
    June 8171
    May 7352
    April 5027
    March 3966
    February 3160
    January 2741


  • 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


  • jQuery to remove mailto

    I wanted to remove a mailto and leave just the email address:

    
    $('a[href^="mailto:"]').contents().unwrap();
    
    

  • 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


  • How to see delegate calendars with your google apps account & an IOS device setup as “Exchange”

    I can never remember this. More of a note to myself. I just got the new iPad (thanks wife!) and when I added my google apps account as an Exchange server, my delegate calendars did not show (for example, the shared family calendar).

    All I needed to do was to visit m.google.com/sync from the iPad, log in, and I can select what calendars my device sees.


  • 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