Showing posts with label MOSS 2007. Show all posts
Showing posts with label MOSS 2007. Show all posts

Tuesday, May 28, 2013

Programatically Expiring Users from Groups in MOSS 2007

Ok,  I was reviewing my posts and found this bit of code I created in my drafts; not sure why I never posted it, but here it is as is.  If you ever wanted to have a list of users that automatically removed user access after a period of time, this code will do it.  I haven't parsed through the code again, but most of this looks good for SharePoint 2010 and should work for 2013.  Let me know if anything has been deprecated and I will recreate and post an update.  The code itself is an example of the actual logic that would be placed in a timer job, looks like I never finished the solution beyond this test, but the logic is there...

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;

public partial class Pull : System.Web.UI.Page

{
protected void Page_Load(object sender, EventArgs e)

{
//Define variables and objects

SPWeb web = SPContext.Current.Web;
SPSite site = web.Site;
string siteUrl = web.Url;
SPList splExpiryList = web.Lists["User Expiration"]; //A Table I created
DataTable dtExpiryList = splExpiryList.Items.GetDataTable();
SPGroup grp = web.Groups[1];int ID=0;
string username = "";
DataTable dtExpired = new DataTable();

//Fields Used in the Table I created

dtExpired.Columns.Add("ID");
dtExpired.Columns.Add("User");
dtExpired.Columns.Add("Group");

foreach (DataRow drExpiry in dtExpiryList.Rows)
{ //"Expiry_x0020_Date" is how sharepoint stores the field "Expiry Date" because there is a space
if (DateTime.Parse(drExpiry["Expiry_x0020_Date"].ToString()) == DateTime.Now)

//Compare the expiry date to current {
username = drExpiry["User"].ToString();

splExpiryList.Items.GetItemById(int.Parse(drExpiry["ID"].ToString()));

ID = int.Parse(drExpiry["ID"].ToString());

try //Let the User know what is being Deleted
{ grp = web.Groups[drExpiry["Group"].ToString()];
Response.Write("Identified and will affect " + drExpiry["Group"].ToString() + " As the Group containing " + drExpiry["User"].ToString() + " to be deleted. . .");
}
catch (Exception ex)
{ Response.Write(ex.Source + "
"
+ ex.Message + "
Stack Trace
"
+ ex.StackTrace + "
+ ex.HelpLink + "\">Help
"); }
try //Create the Expired Users Table
{ DataRow drExpired = dtExpired.NewRow();
drExpired["ID"] = ID;
drExpired["User"] = username;
drExpired["Group"] = grp;
dtExpired.Rows.Add(drExpired);
dtExpired.AcceptChanges();
}

catch (Exception ex)
{ //This should never fail
Response.Write(ex.Source + "
"
+ ex.Message + "
Stack Trace
"
+ ex.StackTrace + "
+ ex.HelpLink + "\">Help

");
}
}
}
foreach (DataRow row in dtExpired.Rows) //Delete Each Expired Item in the table
{ grp = web.Groups[row["Group"].ToString()];
foreach (SPUser user in grp.Users)
{if (user.Name == row["User"].ToString()) //Verify the User exists in the Group
{ web.AllowUnsafeUpdates = true; //Temporarily Allow unsafe updates
Response.Write("Deleting item " + row["ID"].ToString() + " from " + splExpiryList.Title + " . . .");

try
{ splExpiryList.Items.DeleteItemById(int.Parse(row["ID"].ToString())); //Delete the List Item
Response.Write("Success!");
}
catch (Exception ex)
{ Response.Write("Failed!
"
+ ex.Source + "
"
+ ex.Message + "
Stack Trace
"
+ ex.StackTrace + "
+ ex.HelpLink + "\">Help

"); }
 
Response.Write("Deleting user " + user.Name + " from " + grp.Name + " . . .");

try
{ grp.RemoveUser(user); // Remove the user from the Group
Response.Write("Success!");
}
catch (Exception ex)
{
Response.Write("Failed!" + ex.Source + " " + ex.Message + "Stack Trace" + ex.StackTrace + " " + ex.HelpLink + "\">Help");
} 
splExpiryList.Update(); //Update the List
grp.Update(); //Update the Group
web.AllowUnsafeUpdates = false; //Turn off Unsafe Updates

}
else
{
Response.Write("Error! " + user.Name + " not found in group " + grp.Name + "");
}
}
}
 
//Dispose objects dtExpired.Dispose();
dtExpiryList.Dispose();
web.Dispose();
site.Dispose();
}
}


Sorry if this interrupts my governance, but I think this might be useful to someone out there.

Wednesday, March 24, 2010

Some helpful Links for MOSS Administrators

Administrator Guides
· MOSS 2007 - Administrator Guide
· WSS 3.0 - SDK
· WSS 3.0 - Technical Library
· MOSS 2007 - Newly published content
· WSS 3.0 - Newly published content
· WSS 3.0 - SharePoint Server 2007 Developer Portal
· WSS 3.0/MOSS 2007 - Office SharePoint Server 2007 Administrator's Companion
· Complete reference of all PSCONFIG operations


Best Practices
· Before You Begin with SharePoint Server 2007
· Best Practices Analyzer for WSS 3.0 and MOSS2007
· Writing SQL Syntax Queries for Relevant Results in MOSS2007
· Backing Up and Restoring Web Sites w/ Stsadm
· MOSS 2007 - Planning and Architecture for Office SharePoint Server 2007


Search
· Configure the Office SharePoint Server Search service
· Configure Office SharePoint Server Search to crawl Lotus Notes
· Security considerations for search
· Overview: Plan search
· White paper: Evaluation guide for search in Office SharePoint Server
· Plan to deploy index and query servers

STSADM Commands
· Jose Barreto's Blog Complete reference of all STSADM operations (with parameters) in MOSS 2007 SP1

Publishing Templates

When you are working with MOSS 2007 there are two different templates you need to be able to deploy; application templates (WSP files) and site templates (STP files).

While creating an STP file from a site is easy and it makes it available within SharePoint for use, if you script any of your actions, you need to deploy your STP file globally. To do that you are going to need to download the STP file from the site Gallery and then delete it for the gallery. If you don't delete it you will have duplicate templates when we are done.

Once you have the file downloaded you will need to copy it to your web front end server. Once copied we will do the following from the command line using stsadm:

1. Check if the template already exists:
stsadm -o enumtemplates
2. If the template exists, you will need to delete the current copy:
stsadm -o deletetemplate -title {template title}
3. Now you can add the template:
stsadm -o addtemplate -filename {template filename & location} -title {template title} -description {template description}

It will prompt you that an IIS reset is needed at each of these steps, but in reality it is not required and can wait until a time that works for your environment.

The other deployment that you will need to be able to perform is a GAC deployment of an application template. This is also done on the web front end server using stsadm.

1. Add the application template to the solutions list:
stsadm.exe -o addsolution -filename {template filename & location}
2. Deploy the solution to the GAC:
stsadm.exe -o deploysolution -name {template filename} -immediate -allowgacdeployment
3. Copy the Binary Content:
stsadm -o copyappbincontent


So now you know how to deploy global site templates and applicaion template solutions.

Monday, March 8, 2010

My Links are Broken!

Ever have a user come to you and say "My Links are broken!"? If you haven't, just wait, you will...

My Links is a different animal from other Links in MOSS, the actual list behaves differently and if you ever tried to find it in the SQL server you know it is stored differently as well.

To answer your first question... Where is My Links stored? It can be found in your Default SSP inside the UserLinks table, that's right I said the Default SSP.

Now the way the table is built is quite simple, you have your Id, which is the Row identifier and primary key.
The RecordId, which is actually used to identify who owns the link stored in the row. It is not the User's actual Id, but is an Id that is arbitrarily assigned to each user (Makes it tough to find things...).
The Title, which is the first peice of usable information you can use to identify what needs to be changed, this information is the Title the User entered for the name of the Link.
The GroupType identified whether the link is part of a subgroup or not (2 - No Group, 0 - is a Group Member).
The GroupTitle is the name of the Group, it is only populated when the group type is value 0.
The URL is the place we need to go to fix the link. It contains the link info.
The ContentClass and PolicyId must serve a purpose, but I am unconcerned with them right now...
Lastly is the ItemSecurity, which identifies how the user intended to share the link.

To correct a broken link you will need to find the culprit, the user usually knows what link they entered that broke it, but in some cases they may be blissfully ignorant of what they did. A few hints into what breaks my links. The link needs to be invalid, but not a broken link... That means it is valid in most situations, just not in My Links. As an example using file: requires three slashes /// not two, as some people may enter, in most situations two slashes work, but not here... So you should look for any links that are file:// and replace them with file:///.

How do you do that? First you need to run SQL Server Management Studio (for 2005 or 2008) as a user with update permissions to the database, find the link that is causing the problem using either a Script table as -> SELECT TO -> New query editor window or using Open Table. Once you have identified the problem, either delete the row or fix the problem and commit the change.

Hope that helps...

Dave