using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Xml;
namespace
RashuChangeListPermissionWebService
{
class
Program
static
void
Main(
string
[] args)
try
Console.WriteLine(
"This tool will copy the permissions of a list to the other one using web services"
);
RahulPerm1.Permissions sourcePermissions =
new
RashuChangeListPermissionWebService.RahulPerm1.Permissions();
RahulPerm2.Permissions destinationPermissions =
RashuChangeListPermissionWebService.RahulPerm2.Permissions();
"Please enter the url of the source site"
String sourceSiteUrl = Console.ReadLine();
"Please enter the name of the source list"
String sourceListName = Console.ReadLine();
"Please enter the url of the destination site"
String destinationSiteUrl = Console.ReadLine();
"Please enter the name of the destination list"
String destinationListName = Console.ReadLine();
sourcePermissions.UseDefaultCredentials =
true
;
destinationPermissions.UseDefaultCredentials =
sourcePermissions.Url = sourceSiteUrl +
"/_vti_bin/Permissions.asmx"
destinationPermissions.Url = destinationSiteUrl +
XmlNode nodeSource = sourcePermissions.GetPermissionCollection(sourceListName,
"List"
XmlNode nodeDest = destinationPermissions.GetPermissionCollection(destinationListName,
XmlDocument deleteXml =
XmlDocument();
XmlDocument createXml =
XmlElement rootS = createXml.CreateElement(
"Permissions"
XmlElement rootUsers = createXml.CreateElement(
"Users"
XmlElement rootGroups = createXml.CreateElement(
"Groups"
createXml.AppendChild(rootS);
rootS.AppendChild(rootUsers);
rootS.AppendChild(rootGroups);
XmlNodeList nodeDLists = nodeDest.ChildNodes;
String userIdentification;
foreach
(XmlNode nodeDFirst
in
nodeDLists)
(XmlNode nodeDSecond
nodeDFirst.ChildNodes)
userIdentification = nodeDSecond.Attributes[
"MemberIsUser"
].Value;
if
(userIdentification.Equals(
"True"
))
destinationPermissions.RemovePermission(destinationListName,
, nodeDSecond.Attributes[
"UserLogin"
].Value,
"user"
}
else
"GroupName"
"group"
XmlNodeList nodeListsSource = nodeSource.ChildNodes;
XmlAttribute sourceAttribute;
(XmlNode nodeF1
nodeListsSource)
(XmlNode nodeF2
nodeF1.ChildNodes)
sourceAttribute = nodeF2.Attributes[
];
(sourceAttribute.Value.Equals(
XmlElement userD = createXml.CreateElement(
"User"
userD.SetAttribute(
"LoginName"
, nodeF2.Attributes[
].Value);
"PermissionMask"
"Mask"
rootUsers.AppendChild(userD);
XmlElement groupD = createXml.CreateElement(
"Group"
groupD.SetAttribute(
rootGroups.AppendChild(groupD);
destinationPermissions.AddPermissionCollection(destinationListName,
, createXml);
"Execution Completed"
Console.ReadLine();
catch
(Exception e)
Console.WriteLine(e.Message);
Richard Mueller edited Revision 5. Comment: Replaced RGB values with color names in HTML to restore colors
Richard Mueller edited Revision 4. Comment: Removed (en-US) from title
Craig Lussier edited Revision 3. Comment: added en-US to tags and title
Ed Price - MSFT edited Revision 2. Comment: Great article!
Ed Price - MSFT edited Revision 1. Comment: TItle casing and tags