SPNote

SharePoint Notes

SharePoint Custom Field

SPFieldText 를 상속을 하여서 간단히 필드를 하나 만들어 보겠습니다.

 

SPFieldTextSharePoint에서 기본적으로 텍스트 박스 형태의 255길이의 문자를 쓸 수 있는 텍스트 박스 입니다.

 

우선 CS단을 만들고 해당 SPFieldText 를 상속 해 보겠습니다.

  

그리고 빌드를 하면은 에러가 나게 되어있습니다.

베이스 컨트롤의 생성자 들을 안 넣었기 때문입니다. 

 

이런 식으로 넣어 주면은 에러 없이 돌아 갑니다.

 

다음으로 해당 컨트롤에 필드랜더링컨트롤을 오버라이드 해서 상속을 받아서 커스텀

된 해당 필드를 넣어 보도록 하겠습니다.

 

우선 컨트롤을 오버라이드를 하고,

클래스를 하나 만들어서 아래와 같이 소스를 채워 넣습니다.

그 다음 금방 만든 class파일에 가서 basefieldcontrol을 상속 해서 만들어 둡니다.

 

 

텍스트 박스를 바꿔야 하기 때문에 우선 텍스트 박스를 상속하겠다고 선언 하고, 그리고 기본 템플릿을

 SharePoint FieldText 가 사용 하는 “TextField”라는 템플릿을 사용 하도록 하겠습니다.

 

우선 값을 넣을 수 있는 Text라는 인자 값을 리펙터링으로 선언 해서 텍스트박스 값을 집어 넣습니다.

 

 

그리고 value를 오버라이드 해서 해당 값을 채워 줍니다.

 

 

그리고 나서 CreateChildControls를 오버라이드 해서 해당 컨트롤에 뿌려 질 때 할 행동들을 집어 넣을

수 있습니다. (편집과 새로 만들기 시 값을 넣어줘야 함.)

Findcontrol로 해당 필드를 찾아서 넣어 주면은 랜더링이 끝나고 나서 값을 채울 때 해당 필드가 널 값이

 아니기 때문에 값을 넣게 됨( 참고 : 해당 필드 값은 DefaultTemplates.ascx에 정의 되어있음. )

* 기본템플릿에서 TextField로 정의 되어있으니 DefaultTemplates.ascx파일에서 검색을 하시면은 한결 이해가 쉽습니다.

 

  

key파일을 생성 하고 빌드 한 다음 객에 등록을 합니다.

 

 

그리고 xml파일을 하나 만들어서 해당 내용을 집어 넣습니다.

(xml이름은 : fldtypes_아무이름  ß이런 식으로 맞춰주어야지 moss에서 인식을 합니다.)

FieldTypeClass 에 해당 파일의 dll정보 와 해당 class명을 넣어 주고 나서 12 폴더 밑에 xml파일에 넣어 주고 iis reset하면은 끝)

 

 

 

완료1)

완료2)

 

완료3)

 

소스1)

[code:html;In=on]

public class CustomTextField : SPFieldText
{
        public CustomTextField(SPFieldCollection fields, string fieldName)
            : base(fields, fieldName)
        {
        }

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

        public override BaseFieldControl FieldRenderingControl
        {
            get
            {
                BaseFieldControl cbc = new CustomTextBaseControl();
                cbc.FieldName = InternalName;
                return cbc;
            }
        }//FieldRenderingControl

}//class
[/code]

소스 2)

[code:html;In=on]

public class CustomTextBaseControl : BaseFieldControl
{
        protected TextBox customTextField;
       
        protected override string DefaultTemplateName
        {
            get
            {
                return "TextField";
            }
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            if ((base.ControlMode != SPControlMode.Display) && (base.Field != null))
            {
                this.customTextField = (TextBox)this.TemplateContainer.FindControl("TextField");
            }

        }

        public virtual string Text
        {
            get
            {
                this.EnsureChildControls();
                if (this.customTextField == null)
                {
                    return null;
                }
                return this.customTextField.Text;
            }
            set
            {
                this.EnsureChildControls();
                if (this.customTextField != null)
                {
                    this.customTextField.Text = value;
                }
            }
        }

 

        public override object Value
        {
            get
            {
                return this.Text;
            }
            set
            {
                if (base.Field != null)
                {
                    this.Text = base.Field.GetFieldValueForEdit(value);
                }
            }
        }

}
[/code]

소스 3)

[code:xml;In=on]

<?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
 <FieldType>
  <Field Name="TypeName">사용자변경</Field>
  <Field Name="ParentType">Text</Field>
  <Field Name="TypeDisplayName">사용자변경텍스트</Field>
  <Field Name="TypeShortDescription">사용자변경텍스트</Field>
  <Field Name="UserCreatable">TRUE</Field>
  <Field Name="FieldTypeClass">SPnote.SharePoint.SPField.SPFeildText.CustomTextField, SPnote.SharePoint.SPField, Version=1.0.0.0, Culture=neutral, PublicKeyToken=be2c734ef24c0327</Field>
  <RenderPattern Name="DisplayPattern">
   <Column HTMLEncode="TRUE" AutoHyperLink="TRUE" AutoNewLine="TRUE"/>
  </RenderPattern>
 </FieldType>
</FieldTypes> 

[/code] 

이상으로 커스텀 필드에 대해서 마쳤습니다. 내용이 많이 부족 하지만 부족한 내용들은 개인들이 

채워 주시면은 고맙겠습니다.

다음에는 버튼 필드를 만들어 보도록 하겠습니다.                   

 

 

 

 

 

Add comment

Loading