Go to Central Administration
--> Manage Service Applications
--> Managed Metadata Service
--> Under Managed Metadata Service --> New Group
--> Under Group --> New Term Set
--> Under Term Set --> Create Term
--> Remember the Terminology
1. Create a Site Column with "Managed Metadata" Data Type.
2. Add this Site Column to any content type u desire.
3. Add this content type to any list or document library u desire.
Requirement: Update Metadata field in list through Code.
1. VS 2010
2. SharePoint 2010 --> Blank SharePoint Project
3. Features --> Add Feature
4. Add Elements with CustomActionGroup and CustomAction Tags
Note: Id an be any string, don't spend time to give guid.
5. Map to Layout Folders.
6. Add Application Page.
--> In ASPX page add the register tag.
<%@ Register TagPrefix="Taxonomy" Namespace="Microsoft.SharePoint.Taxonomy" Assembly="Microsoft.SharePoint.Taxonomy, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
--> Under Content Main
<Taxonomy:TaxonomyWebTaggingControl ID="myTaxonomyCntrl" runat="server">
</Taxonomy:TaxonomyWebTaggingControl>
--> In ASPX.CS Page Load Method
SPSite site = SPContext.Current.Site;
TaxonomySession session = new TaxonomySession(site);
TermStore termStore = session.TermStores["Managed Metadata Service"];
Group group = termStore.Groups["Group Name"];
TermSet products = group.TermSets["Term Set Name"];
TermCollection termCollection = products.GetAllTerms();
myTaxonomyCntrl.SspId.Add(termStore.Id);
myTaxonomyCntrl.TermSetId.Add(products.Id);
myTaxonomyCntrl.AllowFillIn = true;
myTaxonomyCntrl.IsMulti = false;
Alright, I know..References? Get the Utilities and Taxonomy from 14 Folder.
--> Button clicked Event
SPWeb spweb = SPContext.Current.Web;
SPGroup myVistors = spweb.ParentWeb.Groups["My Visitors"];
SPList SecuredDocs = spweb.Lists["Secured Documents"];
SetPermissions(SecuredDocs,myVistors);
SPField SecuredDocsField = SecuredDocs.Fields["Managed Metadata Column Name"];
SetDefaultValue(SecuredDocsField);
--> SetPermissions
private void SetPermissions(SPList lst, SPGroup grp)
{
try
{
lst.BreakRoleInheritance(true);
lst.RoleAssignments.Remove((SPPrincipal)grp);
lst.Update();
SPRoleDefinitionCollection collection = lst.ParentWeb.RoleDefinitions;
SPRoleDefinition roleDefinition = collection["Custom Permission Level"];
SPRoleAssignment roleAssignment = new SPRoleAssignment((SPPrincipal)grp);
roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
lst.RoleAssignments.Add(roleAssignment);
lst.Update();
}
catch (SPException ex)
{
lblStatus.Text = ex.Message.ToString();
}
}
--> Set DefaultValue of the Manged Metadata Column
private void SetDefaultValue(SPField field)
{
try
{
TaxonomyField TF = (TaxonomyField)field;
TaxonomyFieldValue TFV = new TaxonomyFieldValue(field);
string txt = myTaxonomyCntrl.Text;
string[] ary = txt.Split('|');
TFV.Label = ary[0].ToString();
TFV.TermGuid = ary[1].ToString(); ;
TF.DefaultValue = TFV.ValidatedString;
TF.Update();
}
catch (SPException ex)
{
lblStatus.Text = ex.Message.ToString();
}
}
---> Redirect?
SPUtility.Redirect("settings.aspx", SPRedirectFlags.RelativeToLayoutsPage, this.Context);
--> Build and Deploy ;-)
Subscribe to:
Post Comments (Atom)
SonarQube with Jenkins Setup using Docker Images
https://funnelgarden.com/sonarqube-jenkins-docker/ https://medium.com/@hakdogan/an-end-to-end-tutorial-to-continuous-integration-and-con...
-
Happy New Year. May this year is the year for your dreams, passions, everything you believe, your wishes, your desires, your thoughts, your ...
-
The competitive examination for the Indian Forest Service is conducted by Union Public Service Commission (UPSC). IFS exam is conducted ann...
-
Azure Mobile App Service provides services that allow you to support mobile apps across multiple platforms. It does not provide hosting ser...
No comments:
Post a Comment