Delphi Technology Solutions - development, websites, computers and networks

Development   |   Computers & Networks   |   Websites   |   Products & Services   |   Client Success   |   News

David's Ramblings on Development

SharePoint, InfoPath, .Net and more




Customizing the Content Query Web Part

Share |
clock August 27, 2009 11:51 by author David Lozzi

The content query web part is a beautiful web part, and it's a shame it's only available in MOSS. I would love to use it in WSS. Anyway, the web part will search the entire site collection, or specific sites as you specify, and return items for certain content types, or all, and/or meeting a filter criteria.

As you can imagine, a very useful tool to roll up data and lists from sites all into a central page or dashboard. The issue with this web part is customizing it! There are a few predefined layouts but nothing that is really helpful. Basically, the web part lists the title, as a link to the item, all of the return results. No other fields are included. If you're interested in adding more fields, it requires some customization.

Fortunatly, there are a few SharePoint gurus out there who were nice enough to share how to customize this web part. Their links are below. I recommend reading through both blogs, though they may be repetitive, they compliment each other very well. Then come back and check out my notes below for some more help.

http://paulgalvin.spaces.live.com/Blog/cns!1CC1EDB3DAA9B8AA!491.entry

http://www.heathersolomon.com/blog/articles/CustomItemStyle.aspx

Further reference from Microsoft

http://msdn.microsoft.com/en-us/library/aa981241(classic).aspx

A Few More Notes

The above references are great, they got me where I am. In my experience:

- I used U2U Caml Builder to get the internal name of the field. Specifically, I was rolling up InfoPath forms, and the internal name was a GUID. By using U2U I pulled the internal name out which was _x0033_11111fc_x002d_d892_x002d_4a7e_x002d_a9bc_x002d_d839ee8ef885.

- I think there might be a name length limitation in the ItemStyle.xsl. In my previous note about the GUID name, I had to use the DataColumnRenames property in the .webpart file to get the column to work. <property name="DataColumnRenames" type="string">_x0033_11111fc_x002d_d892_x002d_4a7e_x002d_a9bc_x002d_d839ee8ef885,OpenDate</property>. I can reference OpenDate in the ItemStyle.xsl file.

-Formatting the above date field is easy enough as well. Add xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" to the header of the stylesheet. Then format the date: <xsl:value-of select="ddwrt:FormatDateTime(string(@OpenDate),1033,'M/d/yyyy h:mm tt')" />.

 





Using SharePoint properties to save values instead of web.config

Share |
clock July 6, 2009 09:31 by author David Lozzi

A while back I ran into this issue: I had two web parts in the same project but I wanted them to share settings. As my experience as an ASP.Net developer was pointing me to use the web.config file, instead I thought SharePoint must have something similar to this without me having to mess with the web.config file. After searching and posting on MSDN, I did finally find a solution that uses the properties of SharePoint Sites and Webs.

Below is a sample code that stores the Employee Profile Group in the web so two web parts and an InfoPath form can access the values.

The GetWebProperty function creates the property if it doesn't exist, and if it does it'll return the string value. It's important to call this function before setting a web property, especially the first time it's run so the property is created. I suppose you could technically put the same creation functionality in the SetWebProperty as well, but I was using Get (getting values into my webpart) before my Set (using edit pane to view it).

string employeeProfile = GetWebProperty("EmployeeProfileUserGroup");

SetWebProperty("EmployeeProfileUserGroup", pe.DisplayText);

static string GetWebProperty(string Name)
{
 using (SPSite site = new SPSite(SPContext.Current.Site.ID))
 {
  SPWeb web = site.OpenWeb(SPContext.Current.Web.ID);
  if (web.Properties[Name] == null)
  {
   web.AllowUnsafeUpdates = true;
   web.Properties.Add(Name, "");
   web.Properties.Update();
   web.AllowUnsafeUpdates = false;
   return "";
  }
  else
  {
   return web.Properties[Name].ToString();
  }
 }
}
void SetWebProperty(string Name, string Value)
{
 using (SPSite site = new SPSite(SPContext.Current.Site.ID))
 {
  SPWeb web = site.OpenWeb(SPContext.Current.Web.ID);
  GetWebProperty(Name); //ensure the property exists
  web.AllowUnsafeUpdates = true;
  web.Properties[Name] = Value;
  web.Properties.Update();
  web.AllowUnsafeUpdates = false;
 }
}

If you would like to share the same properties across multiple webs, use the Site.RootWeb object and store all properties there!

Enjoy!





XML web part errors: The XSL specified by the XSL property or XSL Link property is not valid

Share |
clock March 16, 2009 17:17 by author David Lozzi

When using the XML web part in SharePoint, I received the error:

The XSL specified by the XSL property or XSL Link property is not valid, or the XSL file cannot be accessed. Make sure you have specified a valid XSL style sheet for this Web Part, or if the XSL file is linked that it can be accessed by the server. For assistance, contact your site administrator. More about making XSL files accessible.

I received this error after using SharePoint Designer to update the default.aspx page by adding a dataview. The obvious is that there is invalid informtion in my XSL, but it was working fine before I made the updates to the page.

After further examination, it appears that the XSL editor has extra spaces at the top of the page. The <?xml version="1.0" encoding="utf-8"?> should be the very first item in the page, first line first column. It wasn't It was on line two and column 20 or so. So I deleted the extra line and spaces and it worked again.

For some reason SharePoint Designer thought it necessary to mess with my already existing and functioning code. 

Hope this helps!

 





SharePoint page scrolls horizontally with Calendar

Share |
clock December 10, 2008 18:27 by author David Lozzi
By default the calendar is in a list view, and will list the upcoming dates in order. One of the benefits of SharePoint is the clean graphical view of the calendar. It looks like Outlook and is easier to read and understand. We have found many customers enjoy the calendar view instead of the Current Events list view so they switch the view. When the calendar is switched to week or month view, the page get's stretched out and will normally cause the user to have to scroll horizontally to view everything. I run at 1920x1200 and don't have this issue, but someone running at 1024x768 (Which accounts for about 50% of today's users) will.

As you can see above, a user at 1024x768 is missing the right column.
But when you're done here, it'll fit nicely




As you can see there is a fix, but you'll need SharePoint Designer. A note about SharePoint Designer: it's incredibly slow, sometimes it can take 5-10 seconds between clicks. Just bear with it, it works great, but is very slow.

To resolve this, we're going to create a few new rows on the page, and put in some new web part zones so you can throw the calendar in it's own row.

First: open the site using SharePoint designer. You'll want to open it directly to the site, go to File > Open Site. Then type in the complete path to the site, like http://server/site/site2 or where ever it is. When you click Open it might just show you the subfolders of that site. To open the site in SharePoint Designer (SPD) click one of the folders and click Open. Make sure to click a real folder, not a subsite. You will see default.aspx listed, double-click to open that file (yeah, slow eh?). You should see the same page but laid out with some extra borders.



You will notice the calendar doesn't appear. That's because the calendar is actually completely JavaScript driven, meaning your browser creates the calendar view on the fly. SharePoint generates all the code to make it, then your browser translates it into a calendar. Anyway, moving on. 

Right click in the white space below Calendar, select Insert then Row Below. Do the same thing again, and you should now have two rows added to the bottom of the page.



As seen above, there are now two rows under the existing page. Now, click in the second row (the first empty one, not the bottom one) in the first column and drag to the right to select the other two columns. Right click on the highlight and select Modify then Merge Cells. That will create a single cell out of the three. 

Next, click inside the new single large middle cell. Go to the Insert menu, then SharePoint Controls then Web Part Zone. Click in the bottom row, in the first column, and insert another web part zone. Do the same for the third column in the bottom row, so it looks something like this:



Now save the file. SPD wlil alert you stating "Saving your changes will customize a page from the site definition. Are you sure you want to do this?" Click Yes. (if in the future something you did blows up the page, go to Site Settings then Reset to site definition to reset the page). You can now close SPD. 

Go to the page in Internet Explorer. You will notice that nothing looks different. That's Okay. Click Site Actions, then Edit Page. You will see at the bottom of the page, the new zones.



You can now drag your calendar into the middle large zone. This layout also allows you to put some items below your calendar, in the same layout as the top. You should immediately notice the page fits horizontally as soon as you move the calendar into the larger zone. Click Exit Edit mode and Viola! No more scrolling horizontally.



I hope this helps!



RSSRSS Subscribe

About David Lozzi

I love what I do. I'm not the sketchy type that hides in his basement coding all day. I have a beautiful wife and two great children. I've spent my last 10 years plus in the technology arena. more...

Login