-=-=-=-==-==-===-=-ExpirationWorkSpaceTimerJob.cs=============using System;using System.Collections.Generic;using System.Text;using Microsoft.SharePoint;using Microsoft.SharePoint.Administration;using Microsoft.SharePoint.Utilities;namespace ExpirationWorkSpace{ class ExpirationWorkSpaceTimerJob : SPFeatureReceiver { const string _JOB_NAME = "WorkSpace Expiration Timer Job"; //const string _JOB_NAME = "WorkSpace Expiration Date Task"; public override void FeatureActivated(SPFeatureReceiverProperties properties) { try { SPSecurity.RunWithElevatedPrivileges(delegate() { // SPWeb web = null; // SPSite site = null; // SPWebApplication webApplication = this.Parent as SPWebApplication; SPWebApplication webapp = properties.Feature.Parent as SPWebApplication; if (webapp == null) throw new SPException("Error obtaining sp webapp"); // SPWeb web = properties.Feature.Parent as SPWeb; // string siteUrl = web.Site.Url; // SPSite site = new SPSite(siteUrl); //// SPSite site = properties.Feature.Parent as SPSite; // if (site != null) { // make sure the job isn't already registered //foreach (SPJobDefinition job in site.WebApplication.JobDefinitions) foreach (SPJobDefinition job in webapp.JobDefinitions) { if (job.Name == _JOB_NAME) { job.Delete(); } } // install the job ExpirationTaskJob taskLoggerJob = new ExpirationTaskJob(_JOB_NAME, webapp); SPMinuteSchedule schedule = new SPMinuteSchedule(); schedule.BeginSecond = 0; schedule.EndSecond = 59; schedule.Interval = 1; taskLoggerJob.Schedule = schedule; //taskLoggerJob.Properties.Add("siteurl", web.Url); ////taskLoggerJob.Properties.Add("JobID", _jobID); //taskLoggerJob.Properties.Add("JobName", _JOB_NAME); taskLoggerJob.Update(); } }); } catch (Exception ex) { SPUtility.TransferToErrorPage(ex.Message); } } public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { //SPSite site = properties.Feature.Parent as SPSite; //// delete the job //foreach (SPJobDefinition job in site.WebApplication.JobDefinitions) //{ // if (job.Name == wORKSPACE_EXPIRATION_JOB_NAME) // job.Delete(); //} ////throw new Exception("The method or operation is not implemented."); //SPWeb web = null; //SPSite site = null; try { SPSecurity.RunWithElevatedPrivileges(delegate() { //SPWeb web = properties.Feature.Parent as SPWeb; //string siteUrl = web.Site.Url; //SPSite site = new SPSite(siteUrl); //web = properties.Feature.Parent as SPWeb; //site = web.Site as SPSite; //if (site != null) SPWebApplication webapp = properties.Feature.Parent as SPWebApplication; if (webapp == null) throw new SPException("Error obtaining sp webapp"); // SPSite site = properties.Feature.Parent as SPSite; foreach (SPJobDefinition job in webapp.JobDefinitions ) { if (job.Name == _JOB_NAME) { job.Delete(); } } }); } catch (Exception ex) { Microsoft.SharePoint.Utilities.SPUtility.TransferToErrorPage(ex.Message); } } public override void FeatureInstalled(SPFeatureReceiverProperties properties) { // throw new Exception("The method or operation is not implemented."); } public override void FeatureUninstalling(SPFeatureReceiverProperties properties) { // throw new Exception("The method or operation is not implemented."); } }}===========================-=-=-===---------ExpirationTaskJob.cs------------==========
using System;using System.Web;using System.Data;using Microsoft.SharePoint;using Microsoft.SharePoint.Administration;using System.Collections.Specialized;using Microsoft.SharePoint.Utilities;using System.Text;namespace ExpirationWorkSpace{ class ExpirationTaskJob : SPJobDefinition{ public ExpirationTaskJob () : base(){ } /// Name of the job. /// The service. /// The server. /// Type of the target. public ExpirationTaskJob (string jobName, SPService service, SPServer server, SPJobLockType targetType) : base (jobName, service, server, targetType) { } /// /// Initializes a new instance of the class. /// /// Name of the job. /// The web application. public ExpirationTaskJob(string jobName, SPWebApplication webApplication) : base (jobName, webApplication, null, SPJobLockType.ContentDatabase) { this.Title = "WorkSpace Expiration Timer Job"; //this.Title = "WorkSpace Expiration Date Task"; } /// /// Executes the specified content db id. /// public override void Execute (Guid contentDbId) { #if (DEBUG) System.Diagnostics.Trace.Assert(false);#endif // get a reference to the current site collection's content database SPWebApplication webApplication = this.Parent as SPWebApplication; // SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId]; // get a reference to the "Tasks" list in the RootWeb of the first site collection in the content database // SPList taskList = contentDb.Sites[0].RootWeb.Lists["Tasks"]; ////SPList taskList = contentDb.Sites[0].RootWeb.Lists["ExpirationReport"]; SPList taskList = webApplication.Sites[0].RootWeb.Lists["ExpirationReport"]; SPListItemCollection allitems = taskList.Items; DataTable tbl = allitems.GetDataTable(); if (tbl != null) { DataView dv = new DataView(); dv = tbl.DefaultView; // dv.Table.Columns["ExpirationReport"].DataType = Type.GetType("System.DateTime"); dv.RowFilter = "ExpirationDate >='" + DateTime.Now.AddDays(-7) + "'"; DataTable newtbl = new DataTable(); newtbl = dv.ToTable(); int i; if (newtbl.Rows.Count > 0) { for (i = 0; i < sweburl =" newtbl.Rows[i][" _mailbody =" string.Empty;" _mailcontents =" new">"); _mailContents.Append("
"); _mailContents.Append(" Following Workspace is about to expire on date Please do needful "); _mailContents.Append("
using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Web.UI; using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization; using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using Microsoft.SharePoint.WebPartPages; //using System.Collections.Generic; using System.Data; using System.Web.UI.HtmlControls; using System.Text; using Microsoft.SharePoint.Administration; using System.Web.UI.WebControls;
namespace CoPAnnouncer { [Guid("0c6833bc-aa4a-4b77-b2c6-e6d81e263cec")] public class CoPAnnouncer : Microsoft.SharePoint.WebPartPages.WebPart { //private bool _error = false; //private string _myProperty = null; public DataTable tbl; int countDocList = 0; Label lblName = new Label(); HyperLink hlnk = new HyperLink();
public CoPAnnouncer() { this.ExportMode = WebPartExportMode.All; }
/// /// Create all your controls here for rendering. /// Try to avoid using the RenderWebPart() method. /// /// protected override void Render(HtmlTextWriter writer) { ///Creating the main table and adding step by step rows ///along with column and rendering the controls within the ///columns. writer.Write("
using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using Microsoft.SharePoint;using Microsoft.SharePoint.WebControls;using Microsoft.SharePoint.WebPartPages;using System.Collections.Generic;using System.Text;using Microsoft.SharePoint.Administration;using System.Xml;using System.Data.SqlClient;using System.Collections;using System.DirectoryServices;
namespace Sharek{ public partial class ContentManagementAdmin : System.Web.UI.Page { string sLoginName = null;
protected void Page_Load(object sender, EventArgs e) { LblMsg.Text = ""; LblMsg.Text = "Login User " + sLoginName; }
protected override void OnPreInit(EventArgs e) { base.OnPreInit(e);
//if (!HttpContext.Current.User.Identity.IsAuthenticated) //{ // //re-direct the user to log-in page and authenticate // Response.Redirect("/_layouts/accessdenied.aspx"); //} //else { sLoginName = HttpContext.Current.User.Identity.Name; // Added NewLy to get only login username sLoginName = ExtractUserName(sLoginName); // Response.Write(sLoginName);
if (!IsExistInAD(sLoginName)) { Response.Write(" User has no access "); } //Check user against AD group name "HelpDesk" ArrayList UserList = new ArrayList(); UserList = GetADGroupUsers("CACADeDocShareKSiteCollectionAdmin"); // UserList = GetADGroupUsers("CACADeDocShareK"); // UserList = GetADGroupUsers("CACADeDocDivision"); // UserList = GetADGroupUsers("CA/CAD/e-Doc Division"); //UserList = GetADGroupUsers("HelpDesk");
for (int i = 0; i <>"); string value = UserList[i] as string; value.ToUpper().Trim(); sLoginName.ToUpper().Trim(); // Response.Write(" "); // Response.Write("value :- " + value + " "); // Response.Write("sLoginName :- " + sLoginName); if (value.ToUpper() == sLoginName.ToUpper()) { // LblMsg.Text = "Login User " + sLoginName; return; } } //Response.Write("U DON'T HAVE ACCESS"); Response.Redirect("/_layouts/accessdenied.aspx"); } }
protected void Button1_Click(object sender, EventArgs e) { try { LblMsg.Text = ""; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(TextBox1.Text)) { using (SPWeb subWeb = site.OpenWeb())// .Rootweb { subWeb.AllowUnsafeUpdates = true; SPUser UserId = subWeb.EnsureUser((TextBox2.Text)); string strGroup = null; foreach (SPGroup mySPGroup in subWeb.Groups) { foreach (SPRole mySPRole in mySPGroup.Roles) { if (mySPRole.Name == "Content Manager") { strGroup = mySPGroup.ToString(); } } } if (strGroup != null) { SPGroup spGroup = subWeb.SiteGroups[strGroup]; if (!IsUserAuthorized(strGroup, UserId)) { spGroup.AddUser(UserId); //You need to break role inheritence if you want to assign unique permission to subsite if (!subWeb.HasUniqueRoleAssignments) subWeb.BreakRoleInheritance(true); SPRoleAssignment roleAssignment = new SPRoleAssignment(spGroup); roleAssignment.RoleDefinitionBindings.Add(subWeb.RoleDefinitions["Content Manager"]); subWeb.RoleAssignments.Add(roleAssignment); subWeb.Update(); subWeb.AllowUnsafeUpdates = false; LblMsg.Text = "User " + UserId + " Added Succesfully"; } else { LblMsg.Text = "User " + UserId + " Already available"; } } } } }); } catch (Exception err) { // throw err; LblMsg.Text = err.Message; } } protected void Button2_Click(object sender, EventArgs e) { try { LblMsg.Text = ""; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite sps = new SPSite(TextBox1.Text)) { using (SPWeb spWeb = sps.OpenWeb()) { SPUser UserId = spWeb.EnsureUser((TextBox2.Text)); spWeb.AllowUnsafeUpdates = true; string strGrpName = null; foreach (SPGroup mySPGroup in spWeb.Groups) { //spWeb.CurrentUser. foreach (SPRole mySPRole in mySPGroup.Roles) { if (mySPRole.Name == "Content Manager") { //Retrieving all the user groups in the site/web SPGroupCollection userGroups = UserId.Groups; strGrpName = mySPGroup.ToString(); if (IsUserAuthorized(strGrpName, UserId) == true) { //Loops through the grops and check if the user is part of given group or not. foreach (SPGroup group in userGroups) { //Checking the group if (group.Name.Contains(strGrpName)) { strGrpName = mySPGroup.ToString(); mySPRole.Groups[strGrpName].RemoveUser(UserId); LblMsg.Text = "User " + UserId + " Remove Succesfully"; } } } else { LblMsg.Text = "User " + UserId + " could not be found"; } } } } spWeb.AllowUnsafeUpdates = false; } } }); } catch (Exception err) { LblMsg.Text = err.Message; } }
protected void Button3_Click(object sender, EventArgs e) { TextBox2.Text = ""; TextBox1.Text = ""; }
///// ///// Establish identity (principal) and culture for a thread. ///// //public static void SetCultureAndIdentity() //{ // AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); // WindowsPrincipal principal = (WindowsPrincipal)Thread.CurrentPrincipal; // WindowsIdentity identity = (WindowsIdentity)principal.Identity; // System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); //}
public bool IsUserAuthorized(string groupName, SPUser currentUser) { SPGroupCollection userGroups = currentUser.Groups; //Loops through the grops and check if the user is part of given group or not. foreach (SPGroup group in userGroups) { //Checking the group if (group.Name.Contains(groupName)) return true; } return false; }
ArrayList GetADGroupUsers(string groupName) { ///////////////////
////SetCultureAndIdentity();
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using Microsoft.SharePoint.WebPartPages; using System.Collections.Generic; using System.Text; using Microsoft.SharePoint.Administration; using System.Xml; using System.Data.SqlClient; using System.Security.Principal; using System.IO; using System.Diagnostics; public partial class ApplicationWiseStatisstics : System.Web.UI.Page { public static string ListName, sDocumentLibrary; protected void Page_Load(object sender, EventArgs e) { try { WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate(); SPSite rootSite = SPContext.Current.Site; SPWebApplication webApp = rootSite.WebApplication; //SPWebApplicationCollection webApplicationCol = SPWebService.ContentService.WebApplications; DataTable tbl = new DataTable(); tbl.Columns.Add("Title", typeof(string)); tbl.Columns.Add("Url", typeof(string)); tbl.Columns.Add("DocumentCount", typeof(string)); tbl.Columns.Add("TotDocItemCnt", typeof(string)); tbl.Columns.Add("Announcements", typeof(string)); tbl.Columns.Add("TotItemAnnouncements", typeof(string)); tbl.Columns.Add("Links", typeof(string)); tbl.Columns.Add("TotItemLinks", typeof(string)); tbl.Columns.Add("Tasks", typeof(string)); tbl.Columns.Add("TotItemTasks", typeof(string)); tbl.Columns.Add("PictureLibrary", typeof(string)); tbl.Columns.Add("TotItemPictureLibrary", typeof(string)); tbl.Columns.Add("Posts", typeof(string)); tbl.Columns.Add("TotItemPosts", typeof(string)); DataRow row; SPSecurity.RunWithElevatedPrivileges(delegate() { //foreach (SPWebApplication webApp in webApplicationCol) { //Web application name for (int i = 0; i < webApp.Sites.Count; i++) // if (webApp.Sites.Count <= 50) { if (webApp.Sites[i].Url != "http://dha02202-mosd05:500/orgs/30018526/30002982") {
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using Microsoft.SharePoint.WebPartPages; using System.Collections.Generic; using System.Text; using Microsoft.SharePoint.Administration; using System.Xml; using System.Data.SqlClient;
public partial class SiteDetailsOwner : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { SPSite rootSite = SPContext.Current.Site; SPWebApplication webApp = rootSite.WebApplication; //SPWebApplicationCollection webApplicationCol = SPWebService.ContentService.WebApplications; DataTable tbl = new DataTable(); tbl.Columns.Add("Id", typeof(string)); tbl.Columns.Add("Title", typeof(string)); tbl.Columns.Add("Url", typeof(string)); tbl.Columns.Add("RelativeUrl", typeof(string)); //tbl.Columns.Add("ContentDB", typeof(string)); //tbl.Columns.Add("NoSubSites", typeof(string)); //tbl.Columns.Add("Size", typeof(string)); //tbl.Columns.Add("Bandwidth", typeof(string)); //tbl.Columns.Add("Hits", typeof(string)); //tbl.Columns.Add("Visits", typeof(string)); tbl.Columns.Add("MonthlyUsage", typeof(string)); tbl.Columns.Add("NoUsersinRoot", typeof(string)); tbl.Columns.Add("OwnerGrpUser", typeof(string)); DataRow row; SPSecurity.RunWithElevatedPrivileges(delegate() { //commented // foreach (SPWebApplication webApp in webApplicationCol) { //Web application name for (int i = 0; i < finaltotal =" 0;" site =" webApp.Sites[i];" j =" 0;" web =" site.AllWebs[j];" sites =" web.Webs;" itot =" 0;" row =" tbl.Rows.Add();" itot =" PopulateUserUsageData(subSite);" autogeneratecolumns =" false;" visible =" true;" datasource =" tbl;" pageindex =" 0;" pageindex =" e.NewPageIndex;"> /// //Users who visited the site /// /// public int PopulateUserUsageData(SPWeb site) { int totcount = 0; SPSecurity.RunWithElevatedPrivileges(delegate() { DataTable Dt = new DataTable(); //Users who visited the site Dt = site.GetUsageData(SPUsageReportType.user, SPUsagePeriodType.lastMonth); totcount = 0; if (Dt != null) { foreach (DataRow r in Dt.Rows) // Loop over the items. { int itemCount = 0; itemCount = Convert.ToInt32(r["Total Hits"]); totcount += itemCount; } } }); return totcount; } public String SelectData(SPWeb sWeb) { string sName = null; string sAllUsers = null; SPSecurity.RunWithElevatedPrivileges(delegate() { foreach (SPGroup Grp in sWeb.Groups) { if (Grp.Name == Grp.Owner.ToString()) { foreach (SPUser singleUser in Grp.Users) { sName += singleUser.Name + ",";