Contents tagged with SharePoint

  • Dipping Your Toes in the SharePoint 2013 and Office 2013 Preview Goodness

    If you haven’t been living beneath a rock in the last two days, you probably heard the news we released the SharePoint 2013 Preview and Office 2013 Preview. Since there is already a massive amount of content available on blogs, TechNet  etc. I’m not going to add even more with this blog post. My goal is simply to give you a limited amount of resources to quickly get you up to speed with all the news.

    Read more...

  • SharePoint Saturday Belgium was a Big Success!

    Yesterday I had the pleasure to attend and present at the SharePoint Saturday Belgium edition. The Belgium Information Worker Usergroup (BIWUG), who organized the event, deserves a big round of applause; they hosted around 200 enthusiastic SharePoint people on a free and fun event. Of course a big thanks also goes to the numerous sponsors: Xylos (for making their great infrastructure available), AvePoint, Beyond-it, Metalogix, K2, Microsoft, Spikes, Ventigrate, Aurelium, Axceler, CTG, Idera, RealDolmen, Webtrends, and Wrox.

    Read more...

  • URL Shortening For SharePoint 2010

    I’m pretty sure everybody who is using SharePoint has sent a link to a document in a Document Library to somebody else (in an email message for example). So you probably know that links to documents (or list items) can become pretty long if the document is located in a Document Library on a site deeply buried in a hierarchy. SharePoint is of course not the only platform having this “issue” and the internet already solved it quite some time ago with URL shortening. From Wikipedia:

    Read more...

  • Getting Started with jQuery Templates and SharePoint 2010

    Yesterday evening Scott Guthrie announced that Microsoft’s contributions to the jQuery Javascript library were accepted as Official jQuery plugins. One of those contributions is the jQuery Template plugin that allows you to do (up to a certain level) something like data binding similar to the approach we know from Silverlight. The idea is to create a template (think HTML snippet with elements bound to data properties) and data bind that template with an array of objects. You can find the API documentation over here, or you can check out Boris Moore’s excellent Getting Started guide.

    So how can we leverage this in SharePoint 2010? Well jQuery Templates are a great match for either the SharePoint 2010 ECMAScript/Javascript Client Object Model, or the SharePoint 2010 REST API. The following example shows how to quickly display a list of Tasks on a page, by only using jQuery and the REST API in SharePoint 2010. Let’s start with a very basic Site Page that puts an empty ul element in the PlaceHolderMain Content control (notice the ul element gets a specific id set):

    <%@ Page MasterPageFile="~masterurl/default.master" %>
    <asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
        <ul id="tasksUL"></ul>
    </asp:Content>

    Next, we need to put some script references in the PlaceHolderAdditionalPageHead Content control to load both the jQuery library and the jQuery Templates plugin. For now this plugin is a separate .js file, in the next release of jQuery this plugin becomes a part of jQuery itself. (The demo code assumes that both .js files are deployed to the same location as the Site Page.)

    <asp:Content ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
        <script src="jquery-1.4.2.min.js" type="text/javascript"></script>
        <script src="jquery.tmpl.js" type="text/javascript"></script>
    </asp:Content>

    After the script references (also in the PlaceHolderAdditionalPageHead Content control), we need to define our template, also using a script element that has the type attribute set to text/x-jquery-xml. This template is just an HTML snippet that gets created for every object of the array that gets “data bound”. In the template it’s possible to use references to those object’s properties by using template tags. For example ${Title} will get the value of the Title property of the object that gets “data bound”. In the sample below, I’m defining a template that’s basically an li element which displays some properties of a SharePoint Task item. Notice that to display the Description of the Task, I’m using the {{html}} Template Tag, because Description is a Rich Text Field thus it contains HTML itself.

    <script id="tasktemplate" type="text/x-jquery-tmpl">
        <li>
            <b class="ms-rteFontSize-4">${Title}</b> - ${StatusValue}
            <div>{{html Description}}</div>
        </li>
    </script>

    Finally, in a new normal script element (once again in the PlaceHolderAdditionalPageHead Content control), we can use jQuery’s getJSON function to make an async call to the REST API. The getJSON function takes as a parameter a URL to call, which will be the URL of the listdata.svc (= REST API end point) that fetches all Tasks that are not yet completed. The last parameter of the getJSON function is a callback function that will use the jQuery Templates mechanism to build a new li element for every retrieved Task item, based on the template we defined above. This is accomplished by using the new tmpl function, called on the template. The return value is an array of DOM elements, which are added to the empty ul element, defined above.

    <script type="text/javascript">
        $(document).ready(function () {
            $.getJSON(
                "../_vti_bin/listdata.svc/Tasks?$filter=StatusValue ne 'Completed'", null,
                function (data) {
                    $("#tasktemplate").tmpl(data.d.results).appendTo("#tasksUL");
                });
        });
    </script>

    Once the Site Page is deployed, the result will look as follows:

     

    If you’re interested, I’ve created a (slightly enhanced) sample Visual Studio project that’s a Sandboxed Solution (download here, including source code). This project provisions the required .js files, and the Site Page. On the demo Site Page I’ve used the following template:

    <script id="tasktemplate" type="text/x-jquery-tmpl">
        <li>
            <b class="ms-rteFontSize-4" style="cursor:pointer;">
                ${Title}</b> - ${StatusValue}
            <div style="display:none">{{html Description}}</div>
        </li>
    </script>

    Notice that the div element that shows the Description value, is using the style display:none; so initially the Description value is not being displayed. In the callback function, after the li items are built, I’m using jQuery’s toggle function to show and hide the Description div when the corresponding Title is clicked.

    $("#tasktemplate").tmpl(data.d.results).appendTo("#tasksUL");
    $("#tasksUL li").toggle(
        function () {
            $(">div", $(this)).show("fast");
        },
        function () {
            $(">div", $(this)).hide("fast");
        }
    );

    When the Sandboxed Solution is deployed and activated, just navigate to the demo page using the URL http://yoursite/TemplateDemoAssets/demopage.aspx. You’ll see a nicely animated list of Tasks that are not yet completed!

    Read more...

  • Deploying and Using jQuery with a SharePoint 2010 Sandboxed Solution

    If you’re an avid reader of this blog, you probably now that I’m quite a big fan of the jQuery Javascript library, especially in combination with SharePoint sites. For a while I’ve been trying to find a mechanism to deploy jQuery and add a reference to it on all SharePoint pages of a site, by just using a Sandboxed Solution. The first part, deploying the jQuery file, is really easy; this can be done in a Module in a SharePoint project. The second part was more of a challenge; making sure the jQuery file got referenced in all pages of a SharePoint site. My initial thought was to do this by using the AdditionalPageHead Delegate control, but it’s not possible in a Sandboxed Solution (you need to deploy the .ASCX to the SharePoint root). My second thought was to use the new ScriptSrc attribute you can use in a CustomAction (I wrote about this attribute some time ago). But initially I was under the impression that the ScriptSrc attribute could only target Javascript files loaded from the SharePoint Root (the \LAYOUTS) folder, resulting in a no-go for a Sandboxed Solution as well. Daniel McPherson stumbled upon this issue as well, but neatly solved it using Javascript to add the reference dynamically.

    But apparently you can make use of the ScriptSrc attribute to reference files from the Virtual File System (e.g. a Document Library in a site) as well! (thank you Frederic Dobon for mentioning this!). The trick is to use the ~SiteCollection prefix in the ScriptSrc attribute, for example:

    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <CustomAction
        ScriptSrc="~SiteCollection/SiteAssets/jquery-1.4.2.min.js"
        Location="ScriptLink"
        Sequence="10">
      </CustomAction>
    </Elements>

    It’s that easy! For your convenience I’ve uploaded the source code and the resulting SharePoint Solution (WSP file) to CodePlex.

    Read more...

  • "Object reference not set to an instance of an object" when using SharePoint's ClientContext.Current in Silverlight

    SharePoint 2010 and Silverlight is a fantastic combination, especially when you use the Client Object Model for Silverlight to access SharePoint data. But maybe you’ve encountered the following situation: your Silverlight application works great when it’s hosted in the out-of-the-box Silverlight Web Part, but when you build your own custom Web Part to show the Silverlight Application it just doesn’t work anymore: the browser tells you there is an Error on page. The details of the error are: Unhandled Error in Silverlight Application Object reference not set to an instance of an object.

    When you debug your Silverlight code, you’ll notice that the issue is that the ClientContext.Current is a Null Reference. To solution for this problem is that fact that if you want to use the Current ClientContext you need to add the MS.SP.url parameter to the initParams in the HTML object that loads the XAP. This MS.SP.url parameter needs to contain the URL of the site in which the Silverlight Application is currently being displayed. The code of your Silverlight Web Part could look as follows:

    public class SLWebPartDemo : WebPart
    {
      protected override void RenderContents(HtmlTextWriter writer)
      {
        writer.Write(string.Format(
          @"<object data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='100%' height='100%'>
             <param name='source' value='{1}XAPs/SLWebPartDemoControl.xap'/>
             <param name='initParams' value='MS.SP.url={0}/{1}'/>
             <param name='onError' value='onSilverlightError' />
             <param name='background' value='white' />
             <param name='minRuntimeVersion' value='3.0.40818.0' />
             <param name='autoUpgrade' value='true' />
             <a href='http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0' style='text-decoration:none'>
              <img src='http://go.microsoft.com/fwlink/?LinkId=161376' alt='Get Microsoft Silverlight' style='border-style:none'/>
             </a>
            </object>", SPContext.Current.Site.Url,
                        SPContext.Current.Web.ServerRelativeUrl));
      }
    }

    Read more...

  • Upgrading Features in SharePoint 2010

    If you have developed Features for SharePoint 2007, you’re probably aware of a very serious limitation of Feature Development: upgradability. Deploying version 1 of your customization is no problem, but If you want to deploy a bug fix or additional functionality in version 2, you’re basically on your own. The good news is that in SharePoint 2010, this problem is solved: as a developer you can now build features that are upgradable. The basic concept goes as follows, you built your feature as usual, and optionally you’ve got the opportunity to specify what should happen when the feature gets upgraded from a previous version.

    Chris O’Brian has written an excellent series of articles about this topic, so go to his blog to read the details:

    Read more...

  • Easily Adding SafeControls in SharePoint 2010 with Visual Studio 2010

    Many SharePoint developers know that deploying your SharePoint customization to a SharePoint server often requires you to tinker the web.config of the sites where you’d like to see the customization in action. You can do these web.config modifications manually (not advisable), or automate them with the help of the SPWebConfigModification class from the Object Model. But quite often it’s not even necessary to use that class; when you deploy your customizations with the help of a Solution (.WSP file), like you should, the Solution deployment mechanism can modify the Web.Config to apply the most commonly used changes. This is defined in the Solution Manifest of the Solution file. The following Solution Manifest will add for example a SafeControl element for the current Assembly, which is required to display controls like Web Parts, User Controls etc. in the SharePoint sites.

    <Solution xmlns="http://schemas.microsoft.com/sharepoint/" SolutionId="684047e7-a990-4917-8a84-5d2ae5c8b1f3" SharePointProductVersion="14.0">
      <Assemblies>
        <Assembly Location="SafeControlsDemo.dll" DeploymentTarget="GlobalAssemblyCache">
          <SafeControls>
            <SafeControl Assembly="$SharePoint.Project.AssemblyFullName$" Namespace="SafeControlsDemo.EmptyElement1" TypeName="*" />
          </SafeControls>
        </Assembly>
      </Assemblies>
      <FeatureManifests>
        <FeatureManifest Location="SafeControlsDemo_Feature1\Feature.xml" />
      </FeatureManifests>
    </Solution>

    Visual Studio 2010 will automatically add the necessary SafeControl element to the Solution manifest when you add for example a Web Part item to the Visual Studio SharePoint project. But sometimes Visual Studio is not smart enough, or doesn’t have enough information to automatically do this for you. A pretty common scenario is when you build a CustomAction using the ControlClass and ControlAssembly attributes, pointing to a User Control that should be rendering the UI element defined in the CustomAction. In this case you explicitly have to add the required SafeControl element (for the User Control) to the Solution Manifest. As you probably know you can modify the Package.Template.xml to add the required SafeControl elemen, but you have to write that XML manually. A better idea is to use the power of the Visual Studio 2010 SharePoint developer tools, available out-of-the-box! The little trick is to select the item in your SharePoint 2010 project in the Visual Studio Solution Explorer window. The Properties window will show, for the selected project item, a property called Safe Control Entries.

    When you click the ellipsis (the three dots), Visual Studio will show a dialog in which you can easily add the required SafeControl entries. Visual Studio will even fill out default values for you, referencing the assembly of the current project. As a result, the Solution Manifest will be updated with the corresponding XML (you can verify that by opening the Package item and selecting the Manifest view at the bottom). Easy isn’t it?

    Read more...

  • Where did ULSTraceLog go to in the SharePoint 2010 Logging Database?

    The Logging Database is one of the many new concepts that will make the life of many SharePoint administrators quite a bit more enjoyable. In SharePoint 2007 the Unified Logging System (ULS) logged all of its data to text files, typically found on your SharePoint server in 12\LOGS. We still have that in SharePoint 2010, but besides those text files, ULS can also write the data to a database! The advantages are obvious: easy to query, one central location for all servers in the farm, easy to build reports etc. You can find this ULS data in the SharePoint 2010 logging database (typically called WSS_Logging), in the view ULSTraceLog.

    Quite recently on one of my demo machines (standalone installation on Windows 7) I noticed the ULSTraceLog view was not available in the logging database. It turned out that there is a Timer Job that’s responsible for writing the data to the database, when the Timer Job hasn’t executed, the view is not there (the first time it executes, the view is created). Even more, the timer job was disabled, so the view would never be created, nor any data would be written to the database. If you encounter this situation as well, it’s quite easy to solve:

    1. Open the SharePoint Central Administration site
    2. Navigate to the Monitoring section
    3. Select Review Job Definitions
    4. Click on the job with the name Diagnostic Data Provider: Trace Log
    5. Click on the Enable button to enable it
    6. Optionally click on Run Now afterwards, to start it immediately

    There you go, the ULSTraceLog will be created and the ULS messages will appear in the database!

    Read more...