using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.IO;
namespace ConsoleApplication_GetUserandGroup
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite(strSite))
{
using (SPWeb web = site.OpenWeb())
{
try
{
SPUserCollection alluser = web.AllUsers;
foreach (SPUser user in alluser)
{
string strUserandGroup = "";
foreach (SPGroup grp in user.Groups)
{
strUserandGroup = strUserandGroup != "" ? strUserandGroup + "," + grp.Name : grp.Name;
}
strUserandGroup = user.Name + ":" + strUserandGroup;
StreamWriter OurStream;
if (!File.Exists(@"C:\CCS\~IQS-Svn-Code\Console Apps\ConsoleApplication_GetUserandGroup\UserandGroup.txt"))
OurStream = File.CreateText(@"C:\CCS\~IQS-Svn-Code\Console Apps\ConsoleApplication_GetUserandGroup\UserandGroup.txt");
else
OurStream = File.AppendText(@"C:\CCS\~IQS-Svn-Code\Console Apps\ConsoleApplication_GetUserandGroup\UserandGroup.txt");
// OurStream.WriteLine("---------------------------------------------------------");
OurStream.WriteLine(strUserandGroup);
OurStream.Close();
}
}
catch { }
try
{
SPGroupCollection allgroups = web.Groups;
foreach (SPGroup grp in allgroups)
{
StreamWriter OurStream1;
string strGroupUser = "";
foreach (SPUser user in grp.Users)
{
strGroupUser = strGroupUser != "" ? strGroupUser + "," + user.Name : user.Name;
}
strGroupUser = grp.Name + ":" + strGroupUser;
if (!File.Exists(@"C:\CCS\~IQS-Svn-Code\Console Apps\ConsoleApplication_GetUserandGroup\GroupandUsers.txt"))
OurStream1 = File.CreateText(@"C:\CCS\~IQS-Svn-Code\Console Apps\ConsoleApplication_GetUserandGroup\GroupandUsers.txt");
else
OurStream1 = File.AppendText(@"C:\CCS\~IQS-Svn-Code\Console Apps\ConsoleApplication_GetUserandGroup\GroupandUsers.txt");
// OurStream.WriteLine("---------------------------------------------------------");
OurStream1.WriteLine(strGroupUser);
OurStream1.Close();
}
}
catch { }
}
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.IO;
namespace ConsoleApplication_GetUserandGroup
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite(strSite))
{
using (SPWeb web = site.OpenWeb())
{
try
{
SPUserCollection alluser = web.AllUsers;
foreach (SPUser user in alluser)
{
string strUserandGroup = "";
foreach (SPGroup grp in user.Groups)
{
strUserandGroup = strUserandGroup != "" ? strUserandGroup + "," + grp.Name : grp.Name;
}
strUserandGroup = user.Name + ":" + strUserandGroup;
StreamWriter OurStream;
if (!File.Exists(@"C:\CCS\~IQS-Svn-Code\Console Apps\ConsoleApplication_GetUserandGroup\UserandGroup.txt"))
OurStream = File.CreateText(@"C:\CCS\~IQS-Svn-Code\Console Apps\ConsoleApplication_GetUserandGroup\UserandGroup.txt");
else
OurStream = File.AppendText(@"C:\CCS\~IQS-Svn-Code\Console Apps\ConsoleApplication_GetUserandGroup\UserandGroup.txt");
// OurStream.WriteLine("---------------------------------------------------------");
OurStream.WriteLine(strUserandGroup);
OurStream.Close();
}
}
catch { }
try
{
SPGroupCollection allgroups = web.Groups;
foreach (SPGroup grp in allgroups)
{
StreamWriter OurStream1;
string strGroupUser = "";
foreach (SPUser user in grp.Users)
{
strGroupUser = strGroupUser != "" ? strGroupUser + "," + user.Name : user.Name;
}
strGroupUser = grp.Name + ":" + strGroupUser;
if (!File.Exists(@"C:\CCS\~IQS-Svn-Code\Console Apps\ConsoleApplication_GetUserandGroup\GroupandUsers.txt"))
OurStream1 = File.CreateText(@"C:\CCS\~IQS-Svn-Code\Console Apps\ConsoleApplication_GetUserandGroup\GroupandUsers.txt");
else
OurStream1 = File.AppendText(@"C:\CCS\~IQS-Svn-Code\Console Apps\ConsoleApplication_GetUserandGroup\GroupandUsers.txt");
// OurStream.WriteLine("---------------------------------------------------------");
OurStream1.WriteLine(strGroupUser);
OurStream1.Close();
}
}
catch { }
}
}
}
}
}
No comments:
Post a Comment