Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6862373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:39:14+00:00 2026-05-27T02:39:14+00:00

My project requires me to programmatically access TFS servers we don’t administer and to

  • 0

My project requires me to programmatically access TFS servers we don’t administer and to get real time information about the fields in the WorkItemTypes. I can get the field names and most of the information I need by looking at the FieldDefinition in the WorkItemType’s FieldDefinitions collection.

    public WitType(WorkItemType type)
    {
        this.Fields = new List<string>();

        foreach (FieldDefinition f in type.FieldDefinitions)
        {
            Fields.Add(f.Name);
        }
    }

One thing missing is the IsRequired property. I need to be able to tell if a field is required.
I have tried running a work item story query

WorkItemCollection workItemCollection = workItemStore.Query
foreach (WorkItem workItem in workItemCollection)
foreach (Field field in workItem.Fields)
{
     textBox1.Text += field.Name + " is required? " +  field.IsRequired.ToString();                 
}

and then checking the IsRequired property of the Field item in the WorkItem’s Fields collection.
Only problem is that for a given work item type one work item says Title is required, then the next work item will have the IsRequired property = false.

Is there a way to determine if a WorkItem field is required without resorting to the WIT xml file? If not, is there a way to programmatically access the WIT xml file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:39:15+00:00Added an answer on May 27, 2026 at 2:39 am

    I needed to perform a similar task, and the following was the only way I could figure out how to accomplish it.

    As mentioned by others, WorkItem validation is defined in the WorkItemType’s template. Fields can have different validation requirements based on the WorkItem’s current state and even the current user’s permissions.

    Therefore, you need to create/retrieve a WorkItem instance using the user’s credentials. If your application is impersonating the current user (i.e. in an ASP.NET application using Windows Authentication and impersonation), then you can simply use Option 1, where you use the TFS API to get the WorkItem, without impersonating.

    If you’re application is not impersonating the user, when you can use Option 2, where you use the TFS impersonation feature, to make calls on-behave of a user. This requires granting the “Make Requests on behave of others” permission in TFS to the application’s identity (i.e. in ASP.NET the application pool’s identity). See the following link for more information:
    http://blogs.microsoft.co.il/blogs/shair/archive/2010/08/23/tfs-api-part-29-tfs-impersonation.aspx

    The following code is an example on how to do Option 1 and Option 2.

            // Set the following variables accordingly
            string workItemTypeName = "Bug";
            string teamProjectName = "My Project";
            string usernameToImpersonate = "joesmith";
            string tfsTeamProjectCollectionUrl = "http://mydomain.com:8080/tfs/ProjectCollectionName";
    
            // OPTION 1: no impersonation.
            // Get an instance to TFS using the current thread's identity.
            // NOTE: The current thread's identity needs to have the "" permision or else you will receive
            //       a runtime SOAP exception: "Access Denied: [username] needs the following permission(s) to perform this action: Make requests on behalf of others"
            TfsTeamProjectCollection tfs = new TfsTeamProjectCollection( new Uri( tfsTeamProjectCollectionUrl ) );
            IIdentityManagementService identityManagementService = tfs.GetService<IIdentityManagementService>();
    
            // OPTION 2: impersonation.  Remove the following two lines of code if you don't need to impersonate.
            // Get an instance to TFS impersonating the specified user.
            // NOTE: This is not needed if the current thread's identity is that of the user 
            //       needed to impersonate. Simple use the ablve TfsTeamProjectCollection instance
            TeamFoundationIdentity identity = identityManagementService.ReadIdentity( IdentitySearchFactor.AccountName, usernameToImpersonate, MembershipQuery.None, ReadIdentityOptions.None );
            tfs = new TfsTeamProjectCollection( tfs.Uri, identity.Descriptor );
    
            WorkItem workItem = null;
            WorkItemStore store = tfs.GetService<WorkItemStore>();
    
            // Determine if we are creating a new WorkItem or loading an existing WorkItem.
            if( workItemId.HasValue ) {
               workItem = store.GetWorkItem( workItemId.Value );
            }
            else {
               Project project = store.Projects[ teamProjectName ];
               WorkItemType workItemType = project.WorkItemTypes[ workItemTypeName ];
               workItem = new WorkItem( workItemType );
            }
    
            if( workItem != null ) {
    
               foreach( Field field in workItem.Fields ) {
                  if( field.IsRequired ) {
                     // TODO
                  }
               }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a project that requires programmatically distributing a compressed file that
My current project requires extensive use of bit fields. I found a simple, functional
My project requires a file where I will store key/value pair data that should
My project requires a background thread to initiate the creation of a WPF control
One of the data structures in my current project requires that I store lists
I have a project the requires the use of the exec family. My project
I have a project that requires the following. Four arrays will be declared in
I have a project that requires some configuration files. I want to keep the
I'm starting a project which requires reading outlook msg files in c#. I have
I've got a project which requires a fairly complicated process and I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.