Tuesday, September 30, 2008

Customizing the Search Results Web Part

So I was setting up a custom search results (Search Core Results) Web Part the other day to display some fields from a custom content type I created...

I added them to "Selected Columns" as you are supposed to, only to be confronted by the very annoying error message: "Property doesn't exist or is used in a manner inconsistent with schema settings."

This error is of course not particularly helpful, so after some digging I discovered that you can only selected columns that you have created Managed Properties for! (Ref: http://msdn.microsoft.com/en-us/library/ms560074.aspx) Totally lame, but at least now I know why it wasn't working, I must have never added non-managed properties before...

Monday, September 22, 2008

"This item cannot be deleted because it is still referenced by other pages."

So this is one I ran into a while back, and it really annoys me that the top Google link when searching for the error "This item cannot be deleted because it is still referenced by other pages." is the MSDN page telling you to make it "hidden"... This error shows up when trying to delete a Master Page from the Master Page Gallery. Sometimes it will delete just fine, and sometimes you will be presented with this error, even though there are no other pages still referencing it.

The solution is:
  1. Open the site in SharePoint Designer
  2. Navigate to the master page gallery (it is called 'masterpage' under the '_catalogs' folder)
  3. Create a new folder,
  4. Move the Master Page you are trying to delete into this new folder
  5. Then delete the folder
  6. And there you go, SharePoint is now magically ok with deleting the Master Page afterall!

Sunday, September 21, 2008

DataGrid Paging in a Web Part

So this is a simple .NET one, but I ran in to this the other day working on a custom Web Part.

The issue I ran into was doing paging on a DataGrid inside a simple custom Web Part. All of the Web Part's rendering is happening inside of CreateChildControls so I have no aspx/ascx file to set the properties of my DataGrid (which is being created in code) but this is what much of the documentation out there says to do. This is how you do it entirely in code:

For paging to work (besides having the AllowPaging property set) you must specify the method to get called when the paging button is clicked:


myDataGrid.PageIndexChanged += new DataGridPageChangedEventHandler(this.GridChangeMethod);


You can also specify any of the other properties that you would normally do in the aspx file:

myDataGrid.PagerStyle.Mode = PagerMode.NextPrev;
myDataGrid.PagerStyle.NextPageText = "Next >";
myDataGrid.PagerStyle.PrevPageText = "< Prev";

Ref: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.onpageindexchanged.aspx

Thursday, September 18, 2008

Customizing the content query web part (CQWP)

This is a pretty simple one, but people tend to ask about it a lot. One of the most powerful Web Parts built in to MOSS is the Content Query Web Part (affectionately known as the CQWP). This Web Part allows you to roll up content from any and all lists in the current site and all subsites and display in a custom format. If you have never played with it, you should go try it out. You can specify a content type to pull from multiple lists, sort, filter etc...

The greatest thing about the CQWP is that the data comes back as XML and gets displayed using the XSLT in the Style Library (ItemStyle), you can modify this XSLT or point it at your own file to pretty much roll up data in any way you need. This is a great solution to any client that wants you to "write us a web part to display some list data" because it is already written for you and the performance (even when accessing large lists) is pretty much as good as it gets (check out http://go.microsoft.com/fwlink/?LinkId=95450&clcid=0x409 for reference).

The one thing to remember to do is include your custom list columns in the CQWP properties via the .webpart file. There are some good tutorials on doing this (and other property customizations) from MSDN and on Heather Solomon's blog.

Wednesday, September 17, 2008

Getting AccountName from a "Person or Group" field

This is one I ran into a while back and blogged for reference:

Let's say you have a "Person or Group" field on a SharePoint list... How do you get the username of that user in code? Finally found the answer to this buried in MSDN.
Here is the code snippet to convert "Person or Group" type field in a SharePoint list(which is stored like: "12345#;Some Name") into the correct account name in the form of “<Domain>\<Username>”.


SPFieldUserValue userValue = new SPFieldUserValue(workflowProperties.Web,retrievedFieldValue);

string userName = userValue.User.LoginName;


In this case the SPWeb is coming from the workflowProperties, but it just needs the one that the SPList lives in.

About

Hi everyone,

So I wanted to have a quick intro post about who I am and my (at least initial) purpose for this blog… My name is Ely and I work in a large enterprise environment as a “Solutions Developer” which really equates to an Information System’s architect, solution designer, developer, and all around technical “guru”. My main focus is helping users in the business design and build solutions on our enterprise SharePoint platform that consists of the full Windows SharePoint Services 3.0 (WSS 3.0) + Enterprise Microsoft Office SharePoint Server 2007 (MOSS 2007) goodness.

As for this blog, in the never ending learning experience that is SharePoint I seem to keep running into problems, oddities and general “how do I do this?” questions that are not well document or the answers are hard/impossible to find. I plan to use this blog as a place to help others who may have run into the same problems/oddities/”How do I do it” questions that I have run into so they don’t have to go through the same grueling process that I did to solve them.

Please feel free to email me with any comments/feedback you may have or with any problems you would like me to look in to!

-Ely