Wednesday, May 30, 2007

Another reason for "the virtual server that is referenced here is not in the config database."

If you get the error "the virtual server that is referenced here is not in the config database" when you try to use object model, and if the microsoft KB article didn't solve it for you, and you are totaly puzzled...you may have the same problem I have - lack of attention.
This error appeared on my screen because I was developing on a server that has both sharepoint 2003 and sharepoint 2007, and in my project I referanced (without noticing) the DLL for WSS2 and not WSS3.
So ofcourse the code would throw an error it can't find the virtual server in the configuration database! it was looking in the wrong configuration database!
HA!, what a silly person I am...wasted half a day trying to troubleshoot this - going into the database, rebuilding the sites, rebuilding the application, extending the sites, mucking with IIS...untill I noticed the path to the DLL has "60" in it.
BAH!

Monday, May 28, 2007

Meanings of variables in the context menu's script

If you are building a web part that displays context menus for list items - just like the context menus that SharePoint builds out of the box, you need to know the meaning of the attributes that you need to add to the table that holds the item. I couldn't find any documentation or referance to it on the internet, so I decided to publish the results of my diggings.
If you look at the source html of the built-in web part,you will see that every item with a context menu looks like this:

<table height="100%" cellspacing="0" class="ms-unselectedtitle" onmouseover="OnItem(this)" id="1"
ctxname="ctx1"
url="/Documents/Sample%20Document.docx"
dref="Documents"
perm="0x7fffffffffffffff"
type=""
ext="docx"
icon="icdocx.gif|Microsoft Office Word|SharePoint.OpenDocuments"
otype="0"
couid=""
sred=""
cout="0"
hcd=""
csrc=""
ms="0"
ctype="Document"
cid="0x0101006121B9A5B6A75F49AD8620D335B47E62"
uis="1024"
surl="">

The question is asked - what do those attribute mean? what is "cout" and what is "otype"? what values are expected there?

After some research, here is my dictionary:

  • ctxname: Name of the context object on the page that holds the context for the list that you are connecting to.
  • url: link to the document (can be either relative or absolute.
  • dref:File Directory Referance - the relative folder path the item\document is in. For example if I have a document library called "documents" with the url "http://portal/documents", the items in the root folder will have "documents" as the dref value, while items in a folder called "test" will have "documents\test".
  • perm: has to do with permissions, but I didn't figure out how it works yet.
  • type: Seems not to be used for items - but to create menu seperators or different kind of menus.
  • ext: The document extension. For example "doc", "docx", "ppt" and so on.
  • icon: This seems to control the "edit" menu item. Here you specify the icon that will be displayed next to the "edit in..." menu item, the text that will appear as the name of the application (edit in Microsoft Word) and the script that will be used to edit the item (I have no idea what possible values can be used here). All of this seperated by the "|" character.
  • otype: Current Item FSObj Type. This seems to have something to do with the check in-check out menus, that will not be displayed if this is 1, but I could not figure out what is the logic here.
  • COUId: Current Item Checked Out User Id. (ID of the user in the web site the item is from)
  • sred: Server File Redirect. Allows you to specify a URL that will be used instead of the file's url when the link is clicked or when a menu option is used. For example, if you put a link to another document, all menu actions will be redirected to that document instead.
  • cout: Current Item Checkedout To Local. If the item is checked out to a local (offline) folder and not to the database. 0 for false, 1 for true.
  • hcd: Controls if a menu item to navigate to the "/_layouts/updatecopies.aspx" will be added. I am guessing this has to do with records management (update copies of the document when it was changed).
  • csrc: Copy source link. If the item is a copy of an item in a records management site, this holds the link to the source, and adds the menu item for going to the source file (Go to source).
  • ms: Current Item Moderation Status. Also has to do with if its checked out or not, and if its draft or not.
  • ctype: The type of the item. I could not find where that is used.
  • cid: Content Type ID. The ID of the content type for the item. also seems to be used for list menus to determine the content type to create when a user clicks on the new item menu.
  • uis: Current Item UI String. Seems to hold the version number, where the major version is a multiplication of 512, and the minor version is the reminder (the script gets the minor version number by doing "%512"). For example, a value of 512 is version 1.0 while 513 is version 1.1 and 1024 is version 2. Does this mean we have a version limit of 511 minor versions in sharepoint? According to the "introduction to versioning", this is only the default and the administrator can change this. This sounds fishy considering the "512" limit is hard coded in the javascript.
  • surl: Source Url. This dictates where the page will go back to after a menu item is clicked.

Sunday, May 27, 2007

On my dashboard

Just a couple of valuable links to pages I always print out and hang in front of me when I am in a new cubical - a list of SharePoint URLs to get to commonly used administrative functions on a SharePoint site:
SharePoint 2003 URL Quick Links and SharePoint 2007 URL Quick List.

Thanks as always to Heather Solomon.

Wednesday, May 23, 2007

Content Query Web Part xsl for showing the xml

I keep forgetting this, and I think I had to figure it out from scratch at least 4 times allready, so I may as well blog it.
The thing is - last time I figured it out I wanted to blog about it, and then saw that someone beat me to it - Heather Solomon already wrote about it in her blog, and I seem to remember someone else wrote a similar script.
The thing that throws me off every time is realizing that the XML that the content query web part builds for each item has the values in the attributes. So what you need to do is write xslt code to display the attributes.

Heather's article says exactly how to modify the files, so if you need that kind of help, go there now. Below is the code that I am using (slightly modified):

<xsl:template name="ShowXML" match="Row[@Style='ShowXML']" mode="itemstyle">
    <xsl:for-each select="@*">
        </br>
        Name: <xsl:value-of select="name()" /> Value:<xsl:value-of select="." />
    </xsl:for-each>
</xsl:template>

I have just managed to do something really cool with the web part, but I have to refine it a bit before I publish it. I promise this will knock your socks off!

Thursday, May 17, 2007

Mike Fitzmaurice in Canberra

We had a perfect user group meeting here yesterday, with a record breaking number of 65 attendees!

Mike Fitzmaurice, the "developer evangelism contact in Microsoft" gave us 1.5 hours of pure Q&A.
It was very interesting and questions flowed.
Thanks Mike!





Sorry for the poor picture quality - I was there with only my phone...



If you are interested in coming to future user group meetings, go to the registration page in our web site, or let me know. I am now managing the user group, and would love to hear from you what you want to see and hear in our meetings.






What a discount!

This is something a friend noticed when we went to look for an LCD screen for him. What a great discount!







I think you will find this is less then 0.1% discount.





Friday, May 11, 2007

SharePoint Designer Article 2 - Creating an XSLT DataView for a sharepoint list

An XSLT dataview is a great way to modify the look and feel of displayed data in a sharepoint site. The dataview web part is able to display data from either sharepoint lists, or from external data sources.

This article will focus on how to create a simple xslt dataview for a sharepoint list.



First we will create a sharepoint list - Contacts, and fill it with some sample data:





Now, lets create a new page that we will use to create the xslt dataview in:





Open the page in SharePoint Designer (see my previous article if you forgot how - you will need to detach it from the page layout first!).





Now we can add the contacts list to the page using sharepoing designer. You can also do that from the browser before opening the page in sharepoint designer if you prefer:





Let us work in a clean environment - change the properties of the web part so it doesn't display the toolbar. Annoyingly, in sharepoint designer this means you have to open the dropdown menu for the web part (looks like a list icon) and select "change layout":







Select not to show a toolbar.

Now we can transform the web part to an XSLT dataview. Just right-click the web part and choose "convert to xslt data view":





The page should flash and then the web part will appear again, only slightly different. A new menu will appear with a lot more options (filter, sort and group, paging, edit columns, change layout, data view preview, show with sample data, conditional formatting, web part connections, parameters, refresh dataview, dataview properties).
Now you can start playing with it!



In this article I will not go over all the options - I will just conclude by showing you the conditional formatting, and how to deploy the web part to another page in the site:



Click on "Conditional Formatting" in the common data view tasks menu:





The task pane on the right should change to the "Conditional Formatting" pane. Now we can click a row (any will do), and then click the "create" menu, and choose "apply formatting" from the menu:





Because we selected a row, we can apply formatting to that row based on rules we will now define in this screen:





In this example I chose the rule - when first name is "Ishai". Press OK to get to the formatting options:





I set the formatting to show my contact's row with a light blue background, in bold and in uppercase.

Save the file, and view it in the browser:





As you can see - it shows exactly what I wanted it. Now to deploy it to the home page of the site (which we didnt want to detach from the layout page):

In the browser, open the actions menu for the web part and click "export":





Now save the file to your desktop, and go to the homepage of the site. Switch to "edit page mode", click on "add a web part" in one of the zones, and then on the "advanced web part gallery and options" link at the bottom.

Use the dropdown at the top of the pane to switch to web part import pane:





Now, browse to the saved file and click the "upload" button. The web part should appear as an option in the pane. Drag and drop it to the zone you want it in:









And now you can click on "Exit Edit Mode" and see your wonderful new home page, that is still attached to it's layout page!




The next article will show how to do the same, but with external data!






Monday, April 30, 2007

SharePoint Designer Article 1 - how to edit a page?


In SharePoint 2003 (WSSv2) with FrontPage, it was so easy to edit a page. Just open the page you want to edit in Internet Explorer and hit the "Edit in FrontPage" icon at the toolbar.

Well, the good news are that in SharePoint 2007 (WSSv3) the same applies, but only for some of the pages, while other pages will tell you "This page cannot be edited in SharePoint Designer".

This article will explain what is going on, and how to get each type of page to be editable in SharePoint Designer.





Lets start easy- when you create a WSSv3 web site from one of the default template such as team site, blank site etc...you will have no problems using the easy button - edit in SharePoint Designer:



You can also open the SharePoint site or page for editing from within SharePoint Designer using the "Open Site" or "Open.." dialogs within the application:







When you open such a page from such a site directly from Internet Explorer, or from SharePoint Designer, you will see the page in SharePoint Designer, and be able to modify it using the designer mode or the code mode:




So far so good right?

So lets figure out why some of the pages give us the following message when we try to edit them in SharePoint Designer:

"This page cannot be edited in SharePoint Designer. You can edit the content in the browser, or edit the corresponding page layout in SharePoint Designer"

This page cannot be edited in SharePoint Designer. You can edit the content in the browser, or edit the corresponding page layout in SharePoint Designer



Why is that? well, simply because the page you are trying to edit is under the publishing feature. It is a publishing page, and as such, by default, gets it's layout from the layout page and the master page.

The only change you should be doing on such a page is edit it in the browser and add\remove\change web parts in it.


However, there is a way to work around this - detach it from it's layout page. This is similar to the ghosting\unghosting process that we had back in SharePoint 2003 (WSSv2), but with the added benefit that we can allways roll back the change.
It also means that in the first time you will edit that page, you will have to start from SharePoint Designer to do it:


Open the site that contains the page in SharePoint Designer (use "File>Open Site") and browse to the page you want to edit in the folder list.

Right click the file, and choose "Detach from page layout". This will unghost the file - copying it's layout from the layout page into the database, and so allowing you to edit it, just like you used to do in SharePoint 2003:




Unlike sharepoint 2003, you can take it back, and reattach the file:






Best practice:

Although unghosting is no longer a big bad wolf since it can be undone, you still shouldn't be doing it. It means that the page is disconnected from the layout page that defines the layout for all of the pages in the site. If you will want to make a change to the layout template in the future, this page will not change, unless you reattach the file, but in that case your changes to the file's layout will be lost.


So the best practice from SharePoint 2003 remains - only change a file using SPD if you must. There are ways to avoid editing a file in SPD and still making the changes you thought you had to do using SPD. For example - create a new layout page template, and change the page to use that layout.

Now, I hear you asking - "what about dataviews? we can only add them using SPD!". And I will cover that in my next article on the best practice of how to add a dataview using SPD to a page, without detaching it from its layout page.

If you cannot wait until I find the time for this article, just click on the "frontpage" tag in my blog - and see how I did it with sharepoint 2003 and frontpage. The method is the same.






One of more field types are not installed properly

Another FAQ that I see a lot from developers - they get the error "One of more field types are not installed properly" in their applications.
No, don't blame your database in being corrupt, and don't go beat up the guy who create the list and the fields. The problem is simple:
You'r code is doing a CAML query, and uses a field name that does not exist.

I hear you say "but I checked my CAML query, and the field names are correct", and I have to remind you - field names in CAML queries should be internal names, not display names.
This is why, if you have a field called "Parent Task" (for example), in CAML you should refer to it as "Parent_x0020_Task", because the internal name is encoded to avoid special characters.
Also, the internal name may be totaly different from the display name - this will happen if you created a field and then renamed it. So the internal name remains the same as the old name, but the display name changed.
Another scenario for this is when you created your own list definition, and specified different internal and display names. (this happened to me recently)

So, how to know what is the internal name for your field? simple - just click on it!
Let me elaborate - create a view in the list that has that field, and click on the field to sort the list by it. In the web address (url) of the page you are directed to, the internal name of the field should be displayed, after the query string "SortField=".
If the field does not allow sorting, you can go to the list settings and click on the field, as if you want to change it's settings. Again, the internal name of the field will be in the URL address of the page.
Please note, that the field names in the URLs are encoded again, and you will have to compensate for that. for example, a field with a space like "Parent Task" will not be displayed like I said before in the address bar as "Parent_x0020_Task", but instead as "Parent%5fx0020%5fTask" (the underscore character was replaced by the unicode equivalent "%5f").

So you want an easier way to find the internal name (without coding)?
Just do yourself a huge favour and download U2U CAML Builder which is a terrific application to help you build CAML queries.
Since the tool knows it has to use internal names, it just does it for you!.
I cannot live without this tool
U2U CAML Builder screen

Explanation for sharepoint begginers - the difference between web parts and lists (my two web parts are showing the same data)

Did you try adding another web part to a page and it displays the same data as another web part on the page? Here is the answer.

As part of my habit of posting in this site an answer for any question I see more than once in the forums, I want to share with you an explanation I use in the forums to let sharepoint begginers realize what is the difference between a web part and a list.

The confusion sounds like this:
"I'm a newbie to the SharePoint world so if this is a really amateur question, you know why. I am currently tasked with setting up the SharePoint site for my department. I have tried to put two instances of the Links web part on the top level of my site. It will allow me to do this but when I make a change to one of the web parts the change also occurs in the other Links web part." (taken from an msdn forum post)

To which I reply:
You are confusing "web parts" and "lists"
A "web part" is a mechanism to display data, while a "list" is like a small database - a mechanism to store data.

What you did, is have one list (links, or contacts) and two web part displaying the same list - same data.

If you want two different sets of data then the easy way would be to create another list, and add a web part to look into that list.

Another option is to create a field in the list by the name (for example) "show in web part 1" of type boolean, and then configure the two webparts that show the same information to show based on that field (this method is known as a filter).