Feeds:
Posts
Comments

Archive for the ‘Web parts and solutions’ Category

I use the Visual Studio CKSDEV plugin so much that I almost forgot it’s not standard Visual Studio functionality. It’s no doubt the number one tool when creating SharePoint solutions with Visual Studio.

Unfortunately the plugin is not yet updated for Visual Studio 2012 / SharePoint 2013.  But the people at Mavention have created a small tool that mimics the “Copy to GAC” functionality. So it takes at least some of the pain away.

Read all the details on Weldak’s blog:
http://blog.mastykarz.nl/quickly-deploying-sharepoint-2013-projects-mavention-quick-deploy/

Download the tool here:
Mavention Quick Deploy

Update:
As Gary pointed out in the comments below. There is a new kid in town called Fishbone. The reviews, functionality and screenshots look promising. Let’s find out!
http://visualstudiogallery.msdn.microsoft.com/4784e790-32f4-455f-9228-53f537c03787

Read Full Post »

The content search web part is just brilliant. Not only does it let you aggregate, filter and find content and their metadata. The new way of styling with the new display templates is a huge relieve after all the xslt horror in the SharePoint 2007 and SharePoint 2010 versions.

One word of caution: I learned the hard way today that the Content Search Web Part is only available in the SharePoint Enterprise (on-premise) installation.

CSWPFeature

I hope that the nice  folk @Redmond change their mind about this and also make it available for the SharePoint Standard and SharePoint online versions.

The on-premise feature matrix can be found here:
http://technet.microsoft.com/en-us/library/jj819267.aspx#bkmk_FeaturesOnPremise

The online feature matrix can be found here:
http://technet.microsoft.com/en-us/library/jj819267.aspx

Back to the drawing board…

Read Full Post »

Introduction

When in a (localized) variations site, certain “list templates” do not show when trying to create a new list. The “list template” is only available in the master variation with the locale set to English.

Including list templates in your SharePoint (Visual Studio) projects can be straight forward. On a list do a “save as template”, download the ‘stp’ file and add it to your project. However they need to be localized to show in a localized (variations) site.

For information about localization see here : http://msdn.microsoft.com/en-us/goglobal/bb688174

The Solution

To localize the stp files :

  • Download the list template to your local computer.
  • Change the extension of the file from ‘stp’ to ‘cab’.
  • Open the cab file with your compression tool of choice (I use WinRar)
  • Extract the manifest.xml to your hard drive.
  • Open the manifest.xml with Notepad
  • You will notice that there is a <language> tag is defined.
    In my sample this is:
    <Language>1033</Language>
  • Simply change the number between the language tags to the desired ‘locale’.
    Examples:
    Dutch is number 1043
    French is number 1036.

    For a full list of the defined locale numbers look here:
    http://msdn.microsoft.com/en-us/goglobal/bb964664

  • Save the manifest.xml
  • Create new stp file

  • Now we will recreate the cab file with CABARC. See details below.
  • Open the command prompt and type the following command:
    CABARC.EXE N “CarouselTemplateNL.cab” C:\Temp\Project1\CarouselTemplateNL\*.*

  • This will result in a new cab file called: “CarouselTemplateNL.cab”
  • Rename the file back to .stp
  • Upload the file into your list templates gallery
    Site Actions -> Site settings -> Galleries -> List templates -> Upload document

CABARC

“CABARC” is a program from Microsoft to create cab files. Lately it has been replaced by a new program called “makecab”.

CABARC did the job for me but you probably can achieve the same result with makecab

You can download CABARC by downloading the Windows XP Service Pack 2 Support Tools
http://www.microsoft.com/download/en/details.aspx?id=18546
There is no need to install this package. Just unzip the file (and it’s cab files) to your locale machine. One of the unzipped files is CABARC.

Tip for when you don’t know what locales are installed on your SharePoint server.
The quickest way is go to the SharePoint installation folder (aka ’14 hive’) and look in the /TEMPLATE/LAYOUTS folder.

Read Full Post »

Introduction.

In SharePoint 2010 you can use Google Maps without having to download extra webparts or third party tools. In this article I will explain how you can insert “Google Maps” maps in your SharePoint 2011 site with only using standard out of the box SharePoint 2010 features.

It’s a generic solution which can also be used to store HTML code that defines Flash and Silverlight HTML ‘assets’.

1. Get your Google map code.

  • Go to Google maps
  • Find the location you want.
  • In the right hand corner of the map click on “Link”
  • Next click on “Customize and preview embedded map”.
  • Enter the desired options.
  • Copy the HTML code that Google generates for you.
  • Paste the HTML code in a text file (use notepad).
  • Save the text file to your hard drive.

So you have the Google Map HTML code sitting in a text file now. Next step is to upload this file in SharePoint

2. Store the HTML code in SharePoint.

  • Go to your SharePoint site.
  • Click on ‘Site Actions’ =>’More Options’.
  • Click create and create a new Document Library “
  • When the library is created. Click on “Add document”.
  • And upload the Google Map text file you created in the previous step

Your Google Maps HTML code is in SharePoint now.  Next step: display it.

Note 1: An asset might be a more appropiate naming.  So an “Asset Library” might be a better choice. For simplicity sake we stick with a standard “Document Library”
Note 2: Feel free to add your custom content types to the library and fill out out the required meta data.

3. Display the Google Map.

Get the document url :

  • Go the library from the previous step.
  • Click on the Google Maps document you want to display.
  • SharePoint opens this file as plain text in your browser.
  • Copy the url of this file from your browsers address bar.

Add the Google Map to a page :

  • Open the a SharePoint page.
  • Edit the page.
  • Add the Content Editor web part
  • Clicking on “Edit Web part” in the web part context menu
  • Insert the document url, of the Google Maps text document, in the “Content Link” box.
  • Click on OK
  • Save the page.
  • If needed check-in and approve the page.

That’s it. Your Google Map is now visible on the SharePoint site.

The nice thing is that you can reuse this map in your SharePoint site. And when the map changes (change of address, etc…) you only need to change the text file in your Document Library.

Regards,
W0ut

Read Full Post »

While programming in SharePoint, did you ever needed to work your way back to the parent website?

Probably the easiest, but not the recommended, way to do this is:

SPWeb web = SPContext.Current.Web;
while (web != null)
{
   // Do your code here
   web = web.ParentWeb;
}

The problem with this approach is that you are not disposing your SPWeb and SPSite objects. You should correctly dispose you SharePoint objects to avoid memory leaks in your SharePoint customizations.

A better approach that disposes all the objects correctly is this:


private void SomeMethod()
{
   SPSite site = new SPSite(SPContext.Current.Site.ID);
   SPWeb web = site.OpenWeb(SPContext.Current.Web.ID);

   IterateThroughParentsAndStoreInfo(web);

   web.Dispose();
   site.Dispose();
}

private void IterateThroughParentsAndStoreInfo(SPWeb web)
{
   // Do your code for the 'web' variable here.

   if (web.ParentWeb != null)
   {
      using (SPWeb parentweb = web.ParentWeb)
      {
         IterateThroughParentsAndStoreInfo(parentweb);
      }
   }
}

Best practices in SharePoint programing dictate that you have to dispose your SharePoint objects. You can download the free tool SPDisposeCheck that integrates in your Visual Studio and checks if you properly disposed your objects. If not it will give you errors like:

‘Disposable type not disposed: Microsoft.SharePoint.SPWeb’

More information about disposing your objects can be found here.
Hope it helps.

Read Full Post »

Adding a box or rounded corners around a SharePoint web part can be challenging due to the way that SharePoint renders it’s web parts in a <table> layout. This article explains how to add extra <div> elements around the SharePoint web parts. Then by using the ‘sliding doors’ css technique we can add a flexible box arround the SharePoint web part and even include rounded corners.
This tutorial already assumes that you know what SharePoint master pages are and how to work with css and JavaScript files.

Problem.

The HTML code of a SharePoint web part is made out of tables. Depending on the web part options you selected extra  tables and css classes can be added, removed or nested.

The basic HTML markup of a SharePoint web part looks like this

    <table cellspacing="0" cellpadding="0" border="0" width="100%" class="s4-wpTopTable">
        <tbody>
          <tr>
            <td>
            <table cellspacing="0" cellpadding="0" border="0" width="100%">
                <tbody>
                    <tr class="ms-WPHeader">
                    <!-- web part title and menu goes here -->
                   </tr>
                </tbody>
            </table>
            </td>
          </tr>
          <tr>
            <!-- actual web part content goes here -->
          </tr>
        </tbody>
    </table>

This table layout does not leave much room to add a flexible box layout.

The solution.

By using jQuery we can add extra <div> elements to each web part on the SharePoint page. We will use these extra <div> elements  to create a box arround the web part.

For simplicity sake I have put all the needed files together in a folder “boxdemo”. I simply copied these files to the ‘_layouts\styles\’ folder of my SharePoint hive.

Note: putting your files in a folder on the SharePoint server harddrive is not best practice! But for tutorial purposes this will do :-) .  Always use a SharePoint feature when deploying files to a SharePoint server.

The actual box around the web part will be created by simple images. You can use this website to generate the desired images.

For this solution we will need 6 images

  1. l.png   (left image)
  2. r.png (right image)
  3. t.png (top image)
  4. b.png (bottom image)
  5. tl.png   (top left image)
  6. bl.png  (bottom left image)

And also 2 extra files. A stylesheet and a javascript file. you can already create these and leave them empty for now.

  1. style.css
  2. boxing.js

We will add code to these empty files later on.

Adjust your master page

In order to make the boxing work we need to add 3 links to our master page. These links points to the jQuery library, our styling file and our JavaScript file.

Open your master page and add the following links to the <HEAD> section of your master page:

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
    <script src="/_layouts/Styles/boxdemo/boxing.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="/_layouts/Styles/boxdemo/style.css" media="screen" />

I use the jQuery hosted at googleapis.com. In corporate environments this domain is sometimes blocked. If this is the case you should download the jQuery library and put it in the _layouts\styles folder together with the other files.

Javascript

To dynamically add the extra <div> elements arround your webparts we will need a piece of javascript.

Open the (empty) boxing.js file you created earlier and add the following code

/* Add extra div arround webparts so they can be styled with a box. */
$(document).ready(
    function RoundWebPartHeader() {
        $(".s4-wpTopTable").each(function () {
            $(this).addClass("wp-head-round")
            .wrap('<div class=\"box-wp-dialog\">')
            .wrap('<div class=\"box-wp-content\">')
            .wrap(' <div class=\"innerbox\">')
            .parents("div:first").parents("div:first").parents("div:first").prepend('<div class=\"top\"><span>&nbsp;</span></div>')
            .append('<div class=\"bottom\"><span>&nbsp;</span></div>')
        });
    }
);

This JavaScript uses jQuery to find all HTML elements with the css class “s4-wpTopTable”.  By default this css class is assigned  to every web part on the page by SharePoint.

For each HTML element with css class “s4-wpTopTable” the code does the following :

  • adds a css class “wp-head-round”
  • wraps the web part in a <div> with class “box-wp-dialog”
  • wraps the web part again with a <div> with class “box-wp-content”
  • inside the <div> with class “box-wp-dialog”, a new <div class”top”> is added
  • inside the <div> with class “box-wp-dialog”, a new <div class”bottom”> is added

When this is done the SharePoint web part will be encapsulated by various <div> elements.
And the HTML will look like this

<div class="box-wp-dialog">
  <div class="top">
     <span>&nbsp;</span>
  </div>
  <div class="box-wp-content">
    <div class="innerbox">
      <! -- The webpart table HTML is included here -->
      <table cellspacing="0" cellpadding="0" border="0" width="100%" class="s4-wpTopTable">
      </table>
    </div>
  </div>
  <div class="bottom">
    <span>&nbsp;</span>
  </div>
</div>

Go ahead and try it out. Visually there will be no changes (yet). But the extra <div> should be there in the HTML. Keep in mind that the extra HTML elements  are added dynamically on the client side. You will not see these new HTML elements in the source of the page. You need to inspect the HTML with FireBug or with the “Internet Explorer Developer Tools” (F12)

Styling

So now that you have the (extra) <div> elements in our HTML, we can focus on actually styling and creating the box. The last step in our tutorial.

Open the (empty) style.css file and add the following css code.

.box-wp-dialog .top
{
  background-image:url(/_layouts/Styles/boxdemo/tl.png);
  background-repeat: no-repeat;
  background-position: left top;
  height: 12px;padding: 0px 0px 0px 10px;
}
.box-wp-dialog .top span
{
  background-image:url(/_layouts/Styles/boxdemo/t.png);
  background-repeat: no-repeat;
  background-position: right top;
  width: 100%;height: 12px;float:  left;
}

.box-wp-dialog .bottom
{
  background:url(/_layouts/Styles/boxdemo/bl.png) no-repeat left bottom;
  height: 10px;
  padding-left:15px;
}

.box-wp-dialog .bottom span
{
  background:url(/_layouts/Styles/boxdemo/b.png) no-repeat right bottom;
  height: 10px;
  display:block;
}

.box-wp-dialog  .box-wp-content
{
  background: url(/_layouts/Styles/boxdemo/l.png) repeat-y top left;
  padding-left: 2px;
}

.box-wp-dialog  .box-wp-content .innerbox
{
  background: url(/_layouts/Styles/boxdemo/r.png) repeat-y top right;
  background-color: #FFFFFF;
  padding: 5px 5px 0px 10px;
}

This CSS code simply defines the correct background images on our web part to create the illusion of a box.  Save the file and reload your page. Make sure your browser is not using a cached copy.

You should see something similar to this

 

You can change the images to the desired color. Play around with the height, padding, etc…

Happy coding…

Read Full Post »

Ran into a curious issue where I was only able to activate my feature only once after deployment. When I deactivate the feature and then try to activate the feature again, I received the following error :

 Error: A file specified in the modules section of this template already exists.

Resulting in this screen.

Luckily I found the file that was causing the error in the SharePoint logs.

Instantiating module “Style Library”: File already exists at URL “Custom.xsl”, module provisioning failed. 4938b7dd-7642-46aa-9020-a68534c2a726
A file specified in the modules section of this template already exists. 4938b7dd-7642-46aa-9020-a68534c2a726
The element of type ‘Module’ for feature ‘MyCustomFeature’ (id: e2fe1270-6a7e-4461-9542-d8b98a5361c2) threw an exception during activation: A file specified in the modules section of this template already exists.
Feature Activation: Threw an exception, attempting to roll back. Feature ‘MyCustomFeature’ (ID: ‘e2fe1270-6a7e-4461-9542-d8b98a5361c2′). Exception: Microsoft.SharePoint.SPException: A file specified in the modules section of this template already exists

Looking in the elements.xml of my feature I noticed that the attribute “IgnoreIfAlreadyExists” for this file was set to false.

<File Path="Style Library\Custom.xsl" Type="GhostableInLibrary"  IgnoreIfAlreadyExists="false" />

The MSDN documentation about this attribute states: “To provision even if the file aready exists at the specified URL”. Sounds like my error.

So I changed the attribute “IgnoreIfAlreadyExists” to true and…. no more error. Yeah!

<File Path="Style Library\Custom.xsl" Type="GhostableInLibrary"  IgnoreIfAlreadyExists="true" />

Hope it helps…

Read Full Post »

I was writing a new web part to search Taxonomies (Managed metadata) in SharePoint 2010. During testing I got an error when using the class FullTextSqlQuery

“Microsoft.SharePoint.SPException: Your search cannot be completed because this site is not assigned to an indexer. Contact your administrator for more information. at Microsoft.SharePoint.Search.Query.Query.CreateQueryProxy(SPSite site) at Microsoft.SharePoint.Search.Query.Query..ctor(SPSite site)”

while debugging this snippet.

 1: FullTextSqlQuery ftsq = new FullTextSqlQuery(SPContext.Current.Site);
 2: string query = String.Format(" ... " , termTitle);
 3: ftsq.QueryText = query;

A quick search all proposed the same solution: Go to Central Administration and make sure that the “Search Server” is correctly set on the “Manage Content Database Settings” page.
I did try the proposed solution but it didn’t solve my error. Kind of expected, since the search on my development machine was working flawlessly for several weeks.

I googled for quite some time until I discovered that I referenced the wrong dlls. I was developing for the SharePoint 2010 server edition but I referenced the SharePoint 2010 Foundation dlls (= the free version).

Solution.

Change the references of your Visual Studio project from “Microsoft.SharePoint.Search.Query” to “Microsoft.Office.Server.Search.Query”. After this my Web Part worked and the error was gone.
So remember :

Microsoft.SharePoint.Search.Query is for the (free) SharePoint 2010 Foundation development.
and
Microsoft.Office.Server.Search.Query is needed when developing for the SharePoint 2010 server version.

Regards,
W0ut

Read Full Post »

When trying to deploy my SharePoint 2010 solution via Visual Studio 2010 I got the following error.

Error occurred in deployment step ‘Recycle IIS Application Pool’: <nativehr>0×80070005</nativehr><nativestack></nativestack>

Turned out that I forgot to add my user to the “Site Collection Administrators”.

Go to “Site Actions” of the root site , add your user to the list Site Collection Administrators and problem solved.

Read Full Post »

Older Posts »

Follow

Get every new post delivered to your Inbox.