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).

Saturday, April 28, 2007

Content Query Web Part, with a marquee

Meron Fridman has released a free web part - a version of the content query web part that displays the content it found as a marquee. Read about the web part in Meron's blog.
The content query with marquee webpart's properties pane - allows you to set how the marquee works.

Thursday, April 26, 2007

Announcing a new series of articles - SharePoint Designer DataViews

I see a growing amount of questions about the SPD dataviews, or questions that can be answered by "use the dataview web part", so I thought I will start a new series of articles of "how-to"s to show how to do common actions using the dataview web part.

I will start by an article on best practices of using the dataview web part - how you should approach using it. Then I will start showing examples of modifying it, using either the built-in menus, or custom xslt samples.
This is actually an upgrade to some articles I have written in the past on how to use the xslt dataview in frontpage, on this blog and in MSD2D.com.

While I am always open to suggestions on what to show, please keep in mind that I will not do your projects for you. My aim is to show how this cool feature can make your life easier, so don't bother posting complex scenarios of things you want to achieve. Simple questions like "can you explain how to use conditional formatting" or "can you give an example on how to transpose a list, so that the rows are columns" will be (probably) accepted.
Also, if you are asking for something, leave your email address (will not be published) so I can notify you when it's published.

So, keep your eyes opened on this blog (you mean you are not registered by RSS? not even by email? well, it's time!)

Content Query limitations, and Object module access rights requirements

Some new articles were published just now by Microsoft about sharepoint limits that were undocumented until now:
  1. The Content Query Web Part does not support more than 1000 lists at the same time.
    This is actually not a content query web part problem, but a SPSiteDataQuery problem, which the content query web part uses. If you are using SPSiteDataQuery in your code, or a Content Query web part in your page, you may see the error "The query cannot be completed because the number of lists in the query exceeded the allowable limit".
    So you have to be extra careful that your content query web part in not set up to query more than that amount.Read the Microsoft Article (opens in new window).
    Possible error message:
    "The query cannot be completed because the number of lists in the query exceeded the allowable limit. For better results, limit the scope of the query to the current site or list or use a custom column index to help reduce the number of lists."
  2. Error Message when running an application that accesses the object module.
    This is actually something I have encountered with my Utility pack and answered some people in the forums about this, and apperantly MS saw fit to document it properly now.
    When running an appliation on the server that tries to use the object module, you have to run with a user account that has sufficient permissions. Not just on the site, and not just on the server!:
    1. The user is a server farm administrator.
    2. The user has permissions to access the content database.
    3. The user is a site collection administrator.
    4. The user has permissions to access the Windows SharePoint Services site or the SharePoint Server 2007 site through which the code iterates.

    Notice requirement #2? this is where I failed with my utility pack on a client server - I was running the tool with an account that had local administration rights on the server, but the account didn't have any permissions on the database.
    This is also true for running stsadm operations such as backup and restore, or feature deployments... (something they don't say in the article...).
    Read the Microsoft Article (opens in new window).
    Possible error messages:
    "Unhandled Exception: System.IO.FileNotFoundException"
    "Access Denied" (The Microsoft article does not mention this, but I have seen this error for the same issue)

Wednesday, April 25, 2007

Error: "An item with the same key has already been added." When modifying the search results web part's XSLT

When you modify the xslt in the people core results web part, you may get the following error (I get it everytime) when you click "OK" in the web part settings:
System.ArgumentException: An item with the same key has already been added. 
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) 
at Microsoft.Office.Server.Search.WebControls.PeopleCoreResultsWebPart.SetSortedRefinementDataOnHiddenObject() 
at Microsoft.Office.Server.Search.WebControls.PeopleCoreResultsWebPart.GetXPathNavigator(String viewPath)
This is very annoying and I do not know how to solve it. But if you get it, don't worry - your change has been made, and you just need to check-in\publish the page to see the effect. The problem ofcourse is that you may not want to check-in the page without seeing the result first, and there is no way around this...

Monday, April 23, 2007

While I am linking, here is CAML.NET

Another cool tool - go to the the CAML.NET codeplex site and install it.
Now, why didn't I think of that?
Thanks John Holliday.

Using a SharePoint list as an authentication provider

I normally don't post links to other peoples' articles, but when something makes me say "wow" or "why didn't I think of that". This tip is really cool.
It shows in an easy to follow step-by-step process how to make a "users" list in sharepoint, and then make sharepoint (or any other .net application) authenticate users based on that list.
The possibilities are endless. Thank you Willie Rust.

Sunday, April 15, 2007

Changing a list schema in a feature requires IIS reset to take effect

This is more a note to myself than anything smart I have to say:
When you build a list definition, and deploy it as a feature, if you make a change to the schema, the change will not take effect until you do IISRESET.
Deactivating the feature and uninstalling it, then installing it and activating it will not do the trick - you must either recycle the application pool or do IISReset.