locked
Modifying permissions on files/items in version control using the SDK RRS feed

  • Question

  • Using the SDK, I need to change permissions on a specified file/item in version control.  I need to be able to do this for a particular user and for all users. 

    For instance, my app will disallow check in of a specified file for all users.  Later, it would allow checkin of that file by a particular user, check in the file, then allow check in again for all users.

    How do I do this?  Please provide example code.


    EVal99 Any sufficiently advanced technology is indistinguishable from magic. Arthur C. Clarke, "Profiles of The Future", 1961 (Clarke's third law)
    Tuesday, June 14, 2011 6:18 PM

Answers

  • Hello EVal99,

    Thanks for your post.

    To grant permission for a user to access a specific file in the TFS Source Control programmatically, please use the following code.  The sample code is to used to deny domain\username's check out permission for the file: $/TFSReport/WinformApp/WinformApp/Form1.Designer.cs

    using System;
    
    using System.Collections.Generic;
    
    using System.Linq;
    
    using System.Text;
    
    using Microsoft.TeamFoundation.VersionControl.Client;
    
    using System.Net;
    
    using Microsoft.TeamFoundation.Client;
    
    
    
    namespace Model.versionControl
    
    {
    
     public static class GrantFilePermission
    
     {
    
      public static void GrantPermission()
    
      {
    
       NetworkCredential cre = new NetworkCredential("userName", "password", "domain");
    
       TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("tfs2010URL"), cre);
    
       VersionControlServer vcs = tfs.GetService(typeof(VersionControlServer)) as VersionControlServer;
    
       List<SecurityChange> changes = new List<SecurityChange>();
    
       changes.Add(new PermissionChange("$/TFSReport/WinformApp/WinformApp/Form1.Designer.cs", @"domain\user",null , new string[] { "PendChange" }, null));
    
       SecurityChange[] actualChanges = vcs.SetPermissions(changes.ToArray());
    
      }
    
     }
    
    }
    
    

     

    And please also take a look this article for further information about PermissionChange Constructor.

    http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.permissionchange.permissionchange.aspx

    For more information about permission name in the command line, please see:

    http://msdn.microsoft.com/en-us/library/ms252587.aspx
    Thanks,


    Vicky Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Marked as answer by EVal99 Monday, June 20, 2011 7:06 PM
    Thursday, June 16, 2011 2:59 AM
    Moderator