vrijdag 2 oktober 2009

MOSS 2007 need a NoteField to be upgraded to longer the 255 CHars?

I have a client who was busying filling in content when they realized that some field lengths where not long enough. Specifically the NoteField length being used as a descriptions for certain articles (this case pages in a Publishing Web).

I thought the field length was default long enough since in the database it was listed as Text.
After doing some searches I saw some people creating custom field types in order to have a longer NoteField and they where actually using the type NoteField .

That is when I realized that it is in the control not the field type definition. The validation in the control is the only thing limiting the field length here.

So what I did was simply create a new render control that extends the NoteField type and I then override the "validate" function to stop all validating (in this case it removes limiting of the field to 255 chars).

And then voila all my old NoteFields are now nText length instead of 255 chars. You can create the control simply in a dll and throw it in the GAC or the bin. If you include it as a trusted dll in your web.config you can use it in your masterpages, or add it dynamically however you wish. The code is so simple it is not worth showing but what is interesting is that it is possible with out custom field definitions. Anyways the code is something like this:


class LongNoteField :NoteField
{

/*
my class actually includes overrides for all the functions but they are just call
base. so no need to place them in this example.
*/
public override void Validate()
{
//notics the comments here
//base.Validate();
}

public override void UpdateFieldValueInItem()
{
// base.UpdateFieldValueInItem();
// this may not be necessary but i am not really sure what this funcitons is doi
// the base.UpdateFIeldValueIntItem may trim the string or something so i just ignored it.
// simple setting the field item value manually workds as update() is called later.
this.ListItemFieldValue = this.Value.ToString();
}
}

I do this same things with the RichtHtmlFields in which case I then run this.value through an HTML cleaner (Tidy) to make it render valid XHTML. It is easier then paying for a 3rd controls and you can implement it on sites that already have data without having to migrate anything.

So there you go, more than 255 chars anywhere with MOSS 2007.

36 reacties:

  1. 知識可以傳授,智慧卻不行。每個人必須成為他自己。.................................................................                           

    BeantwoordenVerwijderen
  2. 找一個懂妳的人也期許自己做一個人懂別人的人~.........................................

    BeantwoordenVerwijderen
  3. 要求適合自己的愛情方式,是會得到更多,還是會錯過一個真正愛你的人。.................................................................

    BeantwoordenVerwijderen
  4. 做好事,不需要給人知道,雖然只是一件微不足道的事,但我相信,這會帶給我快樂。..................................................

    BeantwoordenVerwijderen
  5. 河水永遠是相同的,可是每一剎那又都是新的。........................................

    BeantwoordenVerwijderen