Posts

Showing posts with the label Web Parts

Change Default Search Scope of your Search Results Page

This, surprisingly, took a lot of digging to come up with, but the solution is simple. 1. Go to your search results page 2. Click Site Actions > Edit Page 3. On the search Core Results web part choose 'Modify Shared Web Part' 4. Expand the Miscellaneous section. 5. Type your scope name in the 'Scope' box, then click apply. 6. Test your Search

Dynamically add a ScriptManager in a WebPart

I've been working on creating a web part that populates a ASP.NET Ajax ReorderList with SharePoint list content, allowing you to reorder based on a column. Since all ASP.Net AJAX components require a ScriptManager you need to either add one to the MasterPage or do it dynamically. I chose to do it dynamically so only the pages that had ASP.Net Ajax components would have it (making the pages a little less bloated). To get a ScriptManager to dynamically add for your web part, add a ScriptManager declaration to your class: ScriptManager _scriptManager; then add this code to your CreateChildControls method: if(_scriptManger == null) { //first check to see if there is a ScriptManager loaded on the page already _scriptManager = ScriptManager.GetCurrent(this.Page); if(_scriptManager == null) { //since there wasn't one on the page, we create a new one and add it to the controls collection _scriptManager = new ScriptManager(); this.Controls.Add(_scriptManager); ...

Content Query Web Part

Sadly there is no built in cross-site list view web part. This seems like a pretty big oversight to me, but there are 3rd party tools that do the trick. However if you want that functionality from out of the box components you have to use a content query web part. Using the content query part is fairly straightforward but there are two things you must remember: The columns you are filtering on have to be site columns If you find some of your list fields aren't available to your itemstyle.xsl, it's likely you'll have to modify the web part's xml. In order to do this complete the following steps. Click the verb menu of the web part and choose to export the part to your file system Open the .webpart file on your file system and find the 'CommonViewFields' property and add your field and its type. Delete the old webpart from your page and reimport the webpart (click Add a web part to this zone then use the advanced settings to import, the import option is in the...

"This solution contains no resources scoped for a Web application and cannot be deployed to a particular Web application." in STSDEV

I recently created a Web Part based on the STSDEV Web Part project and found it was very simple to use. I had another Web Part to create but this time I decided to go with the more generic 'Empty Solution' project just to ensure I wasn't getting lazy with all the stuff STSDEV does for me. The project built, and installed properly into the solution store, but doing a 'DebugDeploy' failed with an error. I compared the two projects and they seemed to be configured identically. However upon further inspection, I found that the 'DebugDeploy' section of the Web Part Project (STS DEV generated) is different than the 'DebugDeploy' section of the empty solution. changing this line: <Exec Command="$(STSADM) -o deploysolution -name $(PackageName) -immediate -allowgacdeployment" /> to: <Exec Command="$(STSADM) -o deploysolution -name $(PackageName) -immediate -allowgacdeployment -allcontenturls" /> solved the problem. NOTE:...

Web Part Styles

There are many examples of how to create a web part. However the best way to style web parts is not necessarily well documented, so I thought I'd offer up my approach and see what the community thinks. Basically I create my web part as a feature in a solution. Then, if my web part generates any code that requires styling I add a .css file to my feature directory. Next I provision the stylesheet of my web part to a folder within my site's "Style Library". Finally I add the code into my web part to add the stylesheet ("<link>") link to the header of the page that my web part has been dropped on. Most of the stuff is straightforward but here's how to provision a style sheet to the style library: Add a "provisioning.xml" file to your feature and reference it in the ElementManifest section of Feature.xml in "provisioning.xml" enter the following: <?xml version="1.0" encoding="utf-8" ?> <Elements xml...

WebPart Error: [ArgumentException: The serialized data is invalid.]

You may run into this problem. In my case I had a legitimate serialization error, but when I took out the offending code I was still getting the same error. I found the solution is to close/readd the webpart to eliminate the error.

Using RSS and XML Web Part

I really like the XML Web Part because of its simplicity - take an XML data source, apply XSLT and have it pretty much whatever you want. I was recently asked to create a jump-to-list-item dropdown box so that you could place the web part on any page and a user could select an item from that list from a dropdown and it would take them to the list item. Here are the steps that it took to create this using the out of the box XML Web Part. Turn on anonymous access on your list ( here's how to do it ) RSS Enable your list and then view the RSS Feed (you can do this through the list's Action menu) Place an XML Web Part on your page Modify the settings of the XML web part by pasting your RSS Feed URL into the webpart's XML Source attribute. Open the XSLT editor and place the following code: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> ...