Posts Tagged ‘MOSS’

Asset Picker field type

In one of my project, I had to create a field type in MOSS with Asset picker functionality. Custom field types are very useful when you are creating custom functionality in MOSS 2007. The following example shows how to provide a functionality to select the document/list item/ from the site. The would be helpful to the user selecting the URL rather typing everything (there is a possibility of typos 🙂 ). We are going to use ‘AssetUrlSelector‘ class from Microsoft.SharePoint.Publishing.WebControls namespace for the purpose.

Create a custom field class by inheriting from SPFieldText class.

public class RelationshipField : SPFieldText {
// Methods
public RelationshipField(SPFieldCollection fields, string fieldName) : base(fields, fieldName) {}

public RelationshipField(SPFieldCollection fields, string typeName, string displayName) : base(fields, typeName, displayName)
{}

// Properties
public override BaseFieldControl FieldRenderingControl
{
get
{
BaseFieldControl control = new RelationshipFieldControl();
control.FieldName = base.InternalName;
return control;
}
}
}

Create a control class by inherting from BaseFieldControl class. and also need to include the following namespaces.

using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing.WebControls;
using Microsoft.SharePoint.WebControls;

Here is how the control creation goes:

public class RelationshipFieldControl : BaseFieldControl
{
protected AssetUrlSelector urlSelector;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// Set the value if this is a postback.

if (this.Page.IsPostBack && base.ControlMode == SPControlMode.Edit)
{
this.ListItemFieldValue = urlSelector.AssetUrl;
}
}
protected override void CreateChildControls()
{
base.CreateChildControls();
// Add the asset picker when in edit mode.
if (base.ControlMode == SPControlMode.Edit)
{
urlSelector = new AssetUrlSelector();
this.Controls.Add(urlSelector);
}
}

protected override void Render(HtmlTextWriter output)
{
// If this is edit mode and has a value, set the picker.
if (base.ControlMode.Equals(SPControlMode.Edit)
&& this.ListItemFieldValue != null)
{
this.urlSelector.AssetUrl = this.ListItemFieldValue.ToString();
}
base.Render(output);
}
}

To register the custom field created above, you need to create a field type definition file as show below. And this xml file needs to be copied to 12\TEMPLATE\XML directory to recognize by MOSS.

The AssetUrlSelector control provides much of the functionality that is necessary for the user to browse and select a document in an Office SharePoint Server library. When you add an instance of this control, a text box and browse button are displayed on the page.
Asset Selector
When users click the Browse button, the Asset Picker dialog box appears and lets the user browse the SharePoint Server libraries and select the related file. The URL to the selected file is automatically set on the AssetUrl property file and appears in the text box.

You might want to scope the URL that is selected with the AssetUrlSelector. To allow users to select a document or item only within the current site collection, you can set the AllowExternalUrls property of the AssetUrlSelector class to false. To narrow the scope even more so that users can only select an item within the current web or a specific list or library, you can implement custom code to validate the selected URL.
The end result of this example is that the path of the related file is stored in the custom RelationshipField. However, the relationship remains unknown to the related file because its metadata is never updated. You can use event handlers to ensure that the related file is updated appropriately when a relationship is created or modified; however, this can become complex. There may be scenarios in which the related file cannot immediately be updated, such as if the user does not have edit permissions on the related file, or the related file is checked out by another user.
At this point, the example is basically a reimplementation of the Hyperlink column functionality. However, by using the AssetURLSelector control (or Asset Picker) in Office SharePoint Server, you can add a UI for selecting the corresponding document in the relationship.
This example is intended to highlight the Asset Picker and the fact that you can use it in custom field controls. You can extend the example to provide additional useful functionality, such as letting users specify multiple-link relationships.

Happy Coding ..!!

~ Gangadhar Kotu

Configuring MOSS 2007 to search pdf documents – install and configure pdf ifilters

 

    1. Download Adobe PDF IFilters 6.0

 

    1. Start –>Run–> Services.msc and stop the IIS Admin service. The reason we need to do this is, the IFilters configuration needs an update to DOCICON.XML.

 

    1. Run the IFilters installer on the Indexing Server

 

    1. Download the pdf icon image pdficon of size 17X17 from the following location and save it as “icpdf.gif” somewhere to the local hard disk http://www.adobe.com/misc/linking.html

 

    1. Copy the icpdf.gif to the following location

 

    1. C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Template\Images”

 

    1. Go the C:\Program Files\Common Files\Microsoft Shared\Web server extensions\12\Template\Xml\

 

    1. Edit the DOCICON.XML by adding the following entry<MAPPING onclick=AtD.suggest(this); pre=”” hiddenSpellError? Key=”pdf” Value=”icpdf.gif”/>

 

    1. Perform an IIS RESET

 

    1. Go to Search Settings under Central Administration and add the pdf as the new file type

 

  1. Perform the crawl again

Now MOSS is supposed to search pdf documents properly. This is what said in so many Articles and Blogs. It did not work for me that easily. After some analysis, I’ve learnt that I need to apply a Microsoft Hot fix to make this work for MOSS 2007. The Microsoft Hot fix mentions the following steps to be performed to make the pdf search work for MOSS 2007

 

    1. Add the following registry entry, and then set the registry entry value to pdf:

 

    1. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\Search\Applications\<GUID>\Gather\Search\Extensions\ExtensionList\38

 

    1. To do this, follow these steps: a. Click Start, click Run, type regedit, and then click OK.

 

    1. Locate and then click the following registry subkey:

 

    1. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\Search\Applications\GUID\Gather\Search\Extensions\ExtensionList

 

    1. On the Edit menu, point to New, and then click String Value.

 

    1. Type 38, and then press ENTER.

 

    1. Right-click the registry entry that you created, and then click Modify.

 

    1. In the Value data box, type pdf, and then click OK.

 

  1. Verify that the following two registry subkeys are present and that they contain the appropriate values.

Note these registry subkeys and the values that they contain are created when you installed the Adobe PDF IFilter on the server.

 

    • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\Search\Setup\ContentIndexCommon\Filters\Extension\.pdf
      This registry subkey must contain the following registry entry:
      Name: Default
      Type: REG_MULTI_SZ
      Data: {4C904448-74A9-11D0-AF6E-00C04FD8DC02}

 

  • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\Search\Setup\Filters\.pdfThis registry subkey must contain the following registry entries:
    • Name: Default
      Type: REG_SZ
      Data: (value not set)
    • Name: Extension
      Type: REG_SZ
      Data: pdf
    • Name: FileTypeBucket
      Type: REG_DWORD
      Data: 0x00000001 (1)
    • Name: MimeTypes
      Type: REG_SZ
      Data: application/pdf
    1. Upload the PDF documents to the Windows SharePoint Services 3.0 Web site.

 

    1. Stop and then start the Windows SharePoint Services Search service. To do this, follow these steps:a. Click Start, click Run, type cmd, and then click OK.

 

    1. Stop the Windows SharePoint Services Search service. To do this, type net stop spsearch at the command prompt, and then press ENTER.

 

    1. Start the Windows SharePoint Services Search service. To do this, type net start spsearch at the command prompt, and then press ENTER.

 

    1. Type exit to exit the command prompt.

 

Now MOSS is ready to search pdf documents. 🙂

~ Gangadhar Kotu