Tuesday, October 21, 2008
SPListItem "System Update"
Thursday, October 2, 2008
Microsoft.SharePoint.WebPartPages.WebPart vs System.Web.UI.WebControls.WebParts.WebPart
So I regularly see people making Web Parts using the Microsoft.SharePoint.WebPartPages.WebPart class instead of the System.Web.UI.WebControls.WebParts.WebPart class. Most of the time people do this because they don't know any better. The Microsoft.Sharepoint one was used for wss 2.0 and it is now recommended that you use the new System.Web.UI.WebControls class (especially since then your web parts will work outside of sharepoint). So the message here is: use System.Web.UI.WebControls.WebParts.WebPart!
That being said, there is one small legitimate use of the Microsoft.SharePoint class (though one that I have never needed to use so far):
The Microsoft.SharePoint.WebPartPages.WebPart class (and NOT the System.Web one) can do:
-
Cross page connections
-
Connections between Web Parts that are outside of a zone
-
Client-side connections (Web Part Page Services Component)
-
Data caching infrastructure, including the ability to cache to the database
Remember, SharePoint is NOT all about the Web Parts!
Tuesday, September 30, 2008
Customizing the Search Results Web Part
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."
The solution is:
- Open the site in SharePoint Designer
- Navigate to the master page gallery (it is called 'masterpage' under the '_catalogs' folder)
- Create a new folder,
- Move the Master Page you are trying to delete into this new folder
- Then delete the folder
- 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
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)
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
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>”.
string userName = userValue.User.LoginName;
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