Sharepoint Guidfield - how to display it in the frontend and set its value in the code?

In a custom form, I want to display my own Guid field.

I created the field in the usual way using the function:

<Field ID="88813c02-799b-4fc8-8ed8-72fe668e257c" Type="Guid" Name="myGuid" StaticName="myGuid" DisplayName="My Guid" /> 

This is the field that I want to first set through the code and display in the form. In the form, I have the following control (for the link, I also include a header):

 <SharePoint:GuidField runat="server" ID="myGuidField" FieldName="myGuid" /> <SharePoint:TextField runat="server" ID="myTitle" FieldName="Title" /> 

The Guid field is not displayed in the usual New / Edit form - it is simply empty. In the code behind the user form, I can do the following:

 myTitle.Value = "Some Title Value"; string testValue = myTitle.Value; //-->"Some Title Value" 

but when you try to set the value of the Guid field, this somehow cannot be done:

 string anotherValue = myGuidField.Value; //--> null Guid myGuid = new Guid("7f824c3f-4049-4034-a231-85291fce2680"); myGuidField.Value = myGuid; string anotherValue = myGuidField.Value; //--> still null //but myGuidField is seen as a "Microsoft.Sharepoint.WebControls.GuidField" 

So, anyway, I just can't set the Guid value programmatically, and I can't only display Guid.

Two questions:

  • How to display a GuidField (containing its GUID) in a form?
  • How to set the value of GuidField
+4
source share
1 answer

GuidField does not override the Value BaseFieldControl property, and this property always returns null and nothing is set for this field control. By default, the GuidField implementation does not have any DisplayTemplates, and if you put this field control in a custom or even standard form, the field will not display any html elements to set the value. The value of the field that you must set manually. To set a custom value, use ItemFieldValue:

 myGuidField.ItemFieldValue = new Guid("7f824c3f-4049-4034-a231-85291fce2680"); 

or simply

 item["myGuid"] = new Guid("7f824c3f-4049-4034-a231-85291fce2680"); 

If you want to edit guid in the form of a user interface (but in most cases it is not required), write a small user field control or try searching on codeplex (since I know that there are no ready-made solutions).

+8
source

Source: https://habr.com/ru/post/1343301/


All Articles