Archive for category Sharepoint

European SharePoint conference in february 2013 comes to Copenhagen

This year the European SharePoint conference comes to Copenhagens Bella Center.

It runs from 4-7th of february 2013

Read more here

Advertisements

Leave a comment

Setting the width of a MultipleLookupField control

When using a MultipleLookupField control in a webpart you can easily make the server create the select / deselect logic for you. The result of rendering a MultipleLookupField control will look something like this.

 

Unfortunately you haven’t got much control over how the control gets rendered and width properties aren’t easily changes. In this case the lookup values are too long and some of the text are therefore unreadable. Changing the width og the two listboxes (Select controls) should be proven rather difficult. However I came up with two different approaches. One where you do it by javascript and one where you can do it server-side in the webpart code.

Clientside approach:

You need to know the select element id for this one so it isn’t really all that useful unless you use something like a Content editor webpart to hold the script. But if you have the problem on just one specific page it can be an easy solution that doesn’t require any coding.

The javascript goes something like this

<script>
var Cand = document.getElementById(‘ctl00_m_g_5b989ee3_2686_4be0_be92_248cf98a2c16_RESEmneLU_ctl00_SelectCandidate’);
Cand.style.width = “300px”;
Cand.parentNode.style.width = “300px”;
var Result = document.getElementById(‘ctl00_m_g_5b989ee3_2686_4be0_be92_248cf98a2c16_RESEmneLU_ctl00_SelectResult’);
Result.style.width = “300px”;
Result.parentNode.style.width = “300px”;
</script>

The rendered MultipleLookupControl automatically gets two HTML select controls (SelectCandidates that holds the candidate values and SelectResult that holds the selected values). You simply changes the width of these two controls and their parent divs. You should of course replace the id’s (ctl00_m_g_5b989ee3_2686_4be0_be92_248cf98a2c16_RESEmneLU_ctl00_SelectCandidate) with your own. Find then by viewing the sourcecode in your browser

Serverside apporach:

The server-side approach is really doing the same just without having the add any Content Editor webparts and without having to know the rendered clientid. All sharepoint controls are initially inherited from the basic Control Class (System.Web.UI.Control) which have the property ClientID that represents the rendered clientID that we had to know with the Clientside approach.

The code for the client side could look something like this

        protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
        {
            this.MyMultipleLookupFieldControl.RenderControl(writer);
            writer.Write(AddJavascript(this.MyMultipleLookupFieldControl.ClientID))
        }

        private string AddJavascript(string clientID)
        {
            string s = “”;
            s += “”;
            s += “<script>\n”;
            s += string.Format(“var Cand = document.getElementById(‘{0}_ctl00_SelectCandidate’);\n”, clientID);
            s += “Cand.style.width = ‘300px’;\n”;
            s += “Cand.parentNode.style.width = ‘300px’;\n”;
            s += string.Format(“var Result = document.getElementById(‘{0}_ctl00_SelectResult’);\n”, clientID);
            s += “Result.style.width = ‘300px’;\n”;
            s += “Result.parentNode.style.width = ‘300px’;\n”;
            s += “</script>”;
            return s;
        }

You can then change the new width values or pass it along the method call to AddJavascript as a parameter.

Regardless of the approach you select the end result should look like this

By the way – You can use the MultipleLookUpField in both a PageLayout and a custom webpart.

In a pagelayout the control could look something like this: <SharePointWebControls:MultipleLookupField runat=”server” id=”MainAreasField” FieldName=”MainAreas”/>
In a webpart the control could look something like this (Placed in the CreateChildControls section): 
                MultipleLookupField MainAreasLookup = new MultipleLookupField();
                MainAreasLookup.ID = “MainAreasLU”;
                MainAreasLookup.ListId = SubscriptionList.ID;
                MainAreasLookup.FieldName = “MainAreas”;
                MainAreasLookup.ControlMode = SPControlMode.Edit;
                MainAreasLookup.ItemId = SubscriptionID;
                this.Controls.Add(MainAreasLookup);

Good luck.

, ,

Leave a comment

Easy access to STSADM when coding sharepoint

When developing sharepoint you cannot avoid using STSADM from time to time. In my case I got tired of navigating to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN to be able to run STSADM commands. If you find some of this familier you can add the above path to your Environment variables and you’ll gain access to STSADM no matter where in Command Prompt you are.

This is what you do.

  1. Start > Controlpanel > System > Advanced tab > Environment variables
  2. On the Systemvariables section find path
  3. Select edit
  4. In the variable value field add: “;C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\” – BE SURE TO ONLY ADD AND NOT OVERWRITE!
  5. Click OK, OK and OK
  6. Reboot your system
  7. From now on you’ll have access to STSADM from anywhere in your command prompt

, ,

Leave a comment

Installing Sharepoint 2010 public beta step by step guide

I found this amazing installation guide that takes you by your hand and shows step by step how to install and setup a complete Sharepoint 2010 public beta.

http://www.sharepointdevwiki.com/display/spadmin2010/Installing+SharePoint+2010+Public+Beta

Priceless!

, , ,

Leave a comment

Event fires 3 times when publishing a publishing page

I’ve spent several days working this out and now I finally figured it out. 

The problem:
I created en eventhandler that should be triggered on ItemUpdated on my Pages library. What the eventhandler did isn’t important in this context but I should mention that it didn’t change anything with the involving item (page) so .DisableEventFiring(); wasn’t an issue. The problem was that every time I opened my page, selected edit page, did some changes and clicked publish my event handler was activated 3 times ?!?! 

So I double checked that I had only added one eventhandler (using Eventhandler Explorer) and did al sorts of analyzing and debugging the code, and it let me absolutely nowhere. 

It was only when I stumbled across this blog that I finally figured out what was going on , and from there on out it all became clear. 

The cause:
When working with publishingpages and eventhandlers you should know that your eventhandler ItemUpdated gets fires 3 times when you are in edit mode and publishes a page.
1 time when the page saves (you can  fire this separate this by choosing save)
1 time when the page are checked in (you fire this separate by choosing Check in to share draft)
1 time when the page are published (you can fire this seperate by choosing publish) 

The solution:
So if you only want your eventhandler to do something when the page are actually published you should use the eventhandler ItemCheckedIn instead of ItemAdded and

 use 

if (properties.ListItem.File.Level == SPFileLevel.Published)
{
  // Do something
}
 

This could be one of those cases when you just googles the wrong subjects but I havent been able to find a lot about this subject so i thought I would share it. I hope you’ll find this helpful and that it can save you some headaches.

, , , ,

Leave a comment

Truncate Sharepoint database logfiles on dev environment

Running my sharepoint developer environment on a virtual machine on my laptop sometimes result in having my drives fill up.

Very often, since I’m not in a production environment I don’t really care about my transaction log files in the sharepoint content databases, and they can grow very large in a short while.

Using SQL Server Management Studio you can easely truncate your logs firing this SQL query, BUT DO SO WITH CARE!

DBCC SHRINKFILE("WSS_ContentDB_log", 1)
BACKUP LOG WSS_ContentDB WITH TRUNCATE_ONLY 
DBCC SHRINKFILE("WSS_ContentDB_log", 1)

DONT EVER DO THIS IN YOUR PRODUCTIONSERVERS!! LEAVE SQL SERVER MANAGEMENT TO DATABASE ADMINISTRATORS

, , ,

Leave a comment