Thursday, November 15, 2007

What's a database?

My wife asked that tonight. She liked how I explained it.

"A database is like a file cabinet. The drawers in the file cabinet are the tables. The folders in the drawers are the records/rows. The papers in the folders are the fields. The fields contain the data."

Make sense?

Saturday, October 27, 2007

MakeCab not updating wsp with updated DLL

Add this to the Pre-build event of your projects. With that bug we've come accross, this seems to take care of it for now.

cd $(TargetDir)
del $(TargetFileName) /q

Saturday, October 20, 2007

My Colleagues Footer Links

Our client wanted those two links under the My Colleagues webpart gone. I added the following javascript to the bottom of my page.

<script language="javascript">
//Grab the tbody of the table
var tbody = document.getElementById("SPS_CLMICSRCHRES").childNodes[0];
if(tbody != null)
{
//Count the rows
var rowCount = tbody.childNodes.length;

//Hide the rows we don't want
tbody.childNodes[rowCount-1].style.display = "none";
tbody.childNodes[rowCount-2].style.display = "none";
tbody.childNodes[rowCount-3].style.display = "none";
tbody.childNodes[rowCount-4].style.display = "none";
tbody.childNodes[rowCount-5].style.display = "none";

//Hide the top row
var headerRow = document.getElementById("tr_updcoll");
if(headerRow != null)
headerRow.style.display = "none";
}
</script>
Couldn't find a better way of doing it. MS didn't provide an option to turn them off. Didn't add an ID to them either.

Monday, September 17, 2007

Hide Site Actions Link

We don't visitors to our site to show the link so I just wrap the control using this control:

<Sharepoint:SPSecurityTrimmedControl runat="server" PermissionsString="BrowseDirectories">

Site Actions

</Sharepoint:SPSecurityTrimmedControl>

The "BrowseDirectories" works for all the roles but Visitor. So it will hide the link for the Visitor role.

Sunday, August 26, 2007

Use your own Code Behind for your Page Layouts or Master Page

You create your Code Behind as normal. You'll need to include the Microsoft.Sharepoint classes that you'll use. Base your Master Page on "System.Web.UI.MasterPage" and your Page Layouts will be "Microsoft.SharePoint.Publishing.PublishingLayoutPage". If you plan to add any controls, do that in the "CreateChildControls()" method. That method is also were you will wire up any events you want for those controls.

Now in your ASPX page, reference the assembly at the top, like:

<%@ Assembly Name"your.assembly.name, version=1.0.0.0, Culture=neutral, Publickeytoken=####" %>

Next add the "Inherits" like:

<%@ Page language="C#" Inherits="your.assembly.name.ClassName"%>

After you build your project, put the DLL in the GAC or the Bin folder of the web application. Then you'll need to reference the DLL in the web.config as a SafeControl.

Now, the page that is using the Page Layout should be using your code behind.

Need a custom ASPX in Sharepoint and not use a Master Page etc?

It's simpler than you may think. The proper way to put the file in the 12-hive would be to use a solution to deploy it (I deployed it as a feature). I'm not going into detail on how to do that part. This how to do it manually.

OK, so create your page as you normally create one. If you want code behind, you'll have to compile the DLL and place it in the Bin/GAC, then you'll need to add a reference to it in the web.config of the application as a safe control. That will cause your web application to load the DLL so you can use it.

After you get it looking how you want, simply copy the aspx page to a location in the 12-hive. Most say use \layouts\Custom\yourpage.aspx. No problems with putting it there.

In your browser the address will look something like this: http://yoursite/_layouts/Custom/yourpage.aspx

Here is an example of one (I don't know how to insert code blocks yet, if you can help, send me an email so I can make the code look better.):

ASPX Page:

<%@ Assembly Name="your.assembly.name (this is the dll for your code behind), version, etc" %>
<%@ Page language="C#" Inherits="your.assembly.name.CLASSNAME(Code Behind)" %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<form>
Hi
</form>
</BODY>
</HTML>

If you don't use a code behind, remove the assembly reference and the "Inherits" property.

If you need more details, let me know.

Saturday, August 25, 2007

Where to store global properties?

Before sharepoint, we used the web.config to store properties. Then in the global.cs, we would store them as application variables (Application["Name"] = ConfigurationSettings.AppSettings["NameValue"];). If we wanted to update the properties, we would have to make the change to the web.config. We all know what happens when you do that.

What I did in Sharepoint (Only because I don't know of a better way. Advice is welcomed) is create a new class called GlobalProperties and based it off of ConfigurationSection. In the constructor, I'm calling a method that reads from a list and stores the name/value of the items in a ConfigurationPropertyCollection. I've also setup a method that will reset the collection since the constructor is only called one time.

I'm not sure this is the best way to do it, but it made sense to me.

No parameterless constructor defined for this object

This error popped up all of a sudden when we tried to create a new page. It was only happening with 1 specific page layout. All the existing pages still worked, so it was only when the page was being created.

I tried a few things to fix this problem, including renaming the namespace, and the class name. I already had an empty constructor in the code.

I decided to delete the page layout from the gallery then redeploy our solution which places the page layout in the gallery. That did the trick. I guess the page layout was corrupted.