19 Mart 2012 Pazartesi

Sharepoint changing max char property of multiline text field


Hi,
Since the default max char limit of any text field in sharepoint is set to 255, in order to increase it there are several ways.

One of them is writing a small csharp code as below:

using (SPSite mySite = new SPSite(siteName)) //site name
                {
                    SPWeb myWeb = mySite.OpenWeb();
                    SPList myList = myWeb.Lists[listName]; // Your document library Name
                    SPField myField = myList.Fields[fieldName]; //Your multiline field name
                    ((SPFieldMultiLineText)myField).UnlimitedLengthInDocumentLibrary = true;
                    myWeb.AllowUnsafeUpdates = true;
                    myField.Update();
                    myWeb.AllowUnsafeUpdates = false;
                }

In my case, I had a multiline field in infopath form and if you promote it with default settings it would have max char length 255.

Better way to achieve this problem, is creating a new custom field, with multiline text option and `Allow unlimited length .. ` property to Yes.

Then,
You can open Infopath and in the Form Options - Promoting settings, you can manually map your multiline field with your custom multiline field.

There you go, now you have a unlimited field !.


In my case, I have used this field to keep the repeating table data as json string, to read it in a custom sharepoint web page.


Third case is:

If you have created the field as singleline and already promoted but you ve realized that you needed as multiline to allow unlimited string, what you need to do is : (yeah, that was my case : ) )

1. Open the Infopath form, change the texbox field to Multiline.
2. Publish the form
3. Open the Sharepoint Manager, find the field and change the readonly property to false
4. Open the list in sharepoint, go to library settings, in the columns section, edit the propery and change it to multiline text by allowing unlimited length.
5. Yeay !

Hiç yorum yok:

Yorum Gönder