SharePoint Calendar View Width

SharePoint calendar widths breaking your custom design? Yea, they’re pretty wide. Here’s how you can tame them.

For the default Month and Day view, you can apply the following style:

.ms-calheader img { width: auto; }

This will reset the width for a spacer image that the fine folks at Microsoft have decided to give this enormous amount of width to.

For the Week view, you need an additional style rule (hold your breath for this one):

.ms-cal-wtopday div img, .ms-cal-wtopdayL div img, .ms-cal-wtopdayLover div img, .ms-cal-wtopdayover div img, .ms-cal-wtopdayRTL div img, .ms-cal-wtopdayRTLL div img, .ms-cal-wtopdayRTLover div img, .ms-cal-wtopdayRTLLover div img, .ms-cal-wtopdayfocusover div img, .ms-cal-wtopdayfocusLover div img, .ms-cal-wtopdayfocusRTLover div img, .ms-cal-wtopdayfocusRTLLover div img, .ms-cal-wtopday-todayRTLover div img, .ms-cal-wtopday-todayRTLLover div img, .ms-cal-wtopday-todayRTL div img, .ms-cal-wtopday-todayRTLL div img, .ms-cal-wtopdayfocusRTL div img, .ms-cal-wtopdayfocusRTLL div img, .ms-cal-wtopdayfocusL div img, .ms-cal-wtopdayfocus div img
{
width: 80px;
}

Holy smokes! Good thing were not optimizing stylesheets for web performance right? This is a cumulative width that is specified for each day column. The value for the width you specify here will by multiplied by 7 to make up the overall width for the view.

Tags:

CSS – Select adjacent element

So, I had a table row with two table cells. The first cell had an class attribute, so I could style it easy enough, but the second table cell had no such class or ID and I need it to style it as well. It should also be noted that i had no means to change the generated html!

Search around a bit and found the CSS adjacent selector. This nifty operator allows me to target the second child within a specified parent. So in my case, the parent was the table row which had an ID, and the children where the two table cells (one with a class and another without). So to get to the second table cell I was able to do:

Sharepoint Dispose

Apparently I was informed that when instantiating an SPWeb or SPSite object, I should call Dispose on those objects to make sure they’re released.

Until one day I stumble upon this lovely error:  “Trying to use an SPWeb object that has been closed or disposed and is no longer valid”

So I google it and find out that I’m trying to dispose the current context of an SPWeb that needs to be used by other controls on the page.

Tags:

Disable javascript debugging Visual Studio 2008 + IE8

So I upgraded to Internet Explorer 8 and now VS is debugging javascript errors for me, read blog article below for help:

http://blogs.msdn.com/greggm/archive/2009/04/06/disabling-script-debugging-in-vs-2008-ie8.aspx

IIS: The process cannot access the file because it is being used by another process.

Got this error while trying to create a website in IIS. Turns out killing my Skype client fixed the problem.

Tags: ,

SharePoint Development

Today at work it was suggested that our SharePoint team (about 3 developers) use a single server on our network as our primary SharePoint development environment. That means all three developers will log on to the same server with different accounts, use Visual Studio and deploy to the same instance of SharePoint, all on the same box.

Those familar with SharePoint development will know that this is a recipe for diaster. Typically, development for SharePoint is done within an isolated Virtual PC and for good reason.

Unfortunately our Systems team got wind of our plans to host local virtuals running Windows Server with SharePoint and the idea was quickly killed as a violation of “policy” (apparently all servers should be managed by our system admin team, even those used exclusively for development).

So, if you find yourself in a similar situation and need ammunition as to why each developer should have an isolated environment, feel free to use the following:

Why Individual Development Environments?

Initial SharePoint development cannot be done on a shared server (with concurrent users) for the following reasons:

  • Global Assembly Cache (GAC) – SharePoint development often requires custom applications and libraries to be deployed to the GAC. If two or more developers are working on a class library that outputs a DLL with the same name, then deploying that DLL to the GAC will only include changes made by a single a developer. Multiple developers will not be able to keep track of current deployments by other developers or be able to test their individual changes.
  • Build & Compilation – Code compilation is an extremely processor intensive task that often requires 100-percent CPU utilization for the length of the compile.  A developer is constantly recompiling code to test and debug, if multiple developers are sharing the same machine, then this would undoubtedly result in constant CPU usage and unusable system performance. Additionally the Visual Studio development environment is an extremely resource intensive application. It is not uncommon for a single instance of Visual Studio to use at least 500MB or to regularly drive high levels of CPU utilization.
  • Unreliable Server Availability – Deploying code often requires IIS services and application pools to be recycled or restarted. In a shared development environment with multiple developers it will be unfeasible for a single developer to effectively test changes or debug problems if other developers could be causing application errors by restarting system services.

Microsoft’s Recommendations:

  • “Most SharePoint developers use a local SharePoint installation. This allows them to build, test, and debug their work without affecting the work of anyone else on the team. The local environment can be installed on either the developer’s host workstation or on a virtual computer that runs on either Microsoft Virtual PC 2007 or Microsoft Virtual Server 2005 R2.”
    (http://msdn.microsoft.com/en-us/library/dd239299.aspx)
  • “When each developer has her own instance of SQL Server 2005 and Office SharePoint Server 2007 or Windows SharePoint Services 3.0, this configuration helps prevent conflicts during development, mitigates performance issues during debugging, and ensures that the solution works in multiple environments.”
    (http://msdn.microsoft.com/en-us/library/bb330848.aspx)
  • “First and foremost, you need to develop locally for the “best” debugging and testing experience. Development is done in a virtual machine using the Win2003 OS and WSS/MOSS installed.  Each developer should have their own virtualized environment…”
    (http://blogs.msdn.com/scaravajal/archive/2008/04/27/creating-a-sharepoint-development-environment.aspx)
  • “Working locally…you can configure the development environment so that all of the SharePoint development work can be done locally…We recommend this configuration for a number of reasons…”
    (http://msdn.microsoft.com/en-us/library/bb530302.aspx)

Feel free to add any other suggestions…

Tags: ,

Debugging in SQL Management Studio

One common frustration is trying to debug SQL queries using the built-in editor within Microsoft SQL Server 2005 Management Studio. The database will kindly inform you of any errors when you attempt to execute a query, and also provide a line number. But that’s about it.

Compared to the error highlighting features available in Visual Studio,  its hard to imagine that Management Studio is developed by the same company.

For example take the following error:

Example of Sql Error

Example of Sql Error

The editor informs me that I have two errors, one on Line 4 and another on Line 2. But here’s the thing – if I go to line 2 or 4 of my script, I find nothing pertaining to the error. So what’s going on?

The query parser conveniently restarts counting line numbers whenever it encounters a code block, so anything in between a BEGIN and END statement, starts at line 0 again. If you have multiple code blocks in a script, then line numbers are completely useless.

So how do you find out which line is actually causing the error?

In the most poorly designed way ever imagined,  Microsoft has graciously decided to help you out by allowing you to double click on those error messages and be taken to the exact part of your code that is causing the error.

And then that leads one to wonder – if there is some way for this double-click function to map the error message to the actually line number in the editor, then why isn’t this function used to display the “real” line numbers for error messages, as opposed to the completely useless line numbers that are shown now?

Considering the amount of money organizations spend on SQL Server, I find this type of design short-sighted.

T-SQL Return True / False based on Is Null

So I’m working on a project where images are uploaded to a database table. The table has an image column, and if there is no image, then the column is just null,  but otherwise the bytes for the image are stored.

An ASPX page takes in the row id for this table via querystring and serves up the bytes from the column as an actual image.

On a separate page, I’m displaying the contents of the table in a per-record listing, if there is an image, then I display a thumbnail by calling the aforementioned aspx image page.

So my problem? If only some records have images, then how do I know when to call the aspx image page? I could do something quick like:

SELECT ItemID, ItemName, ItemDescription, ItemImage FROM Table

And then check to see if ItemImage is null. But what if it isn’t null? I can’t do anything with the bytes I have, because I have a separate page for displaying the image. So in essence, I’m calling back data (potentially large data) that I don’t need.

So what I really want is a query that looks like:

SELECT ItemID, ItemName, ItemDescription, HasImage FROM Table

Where HasImage is a bit (true/false) column, telling me if there’s an image for this item or not. But I don’t have a column in my table called HasImage and its too much work to implement one.

So the best way to solve this?

SELECT ItemID, ItemName, ItemDescription, (CASE WHEN ItemImage IS NOT NULL THEN 1 ELSE 0 END) AS HasImage FROM Table

This now tells me if this record has an image without actually bringing back the bytes for the image.