using System; using System.ComponentModel; using System.ComponentModel.Design; using System.Collections; using System.Collections.Generic; using System.Text; using System.Drawing; using System.Workflow.ComponentModel.Compiler; using System.Workflow.ComponentModel.Serialization; using System.Workflow.ComponentModel; using System.Workflow.ComponentModel.Design; using System.Workflow.Runtime; using System.Workflow.Activities; using System.Workflow.Activities.Rules; using Microsoft.SharePoint; using Microsoft.SharePoint.Workflow; using Microsoft.SharePoint.WorkflowActions; using Microsoft.SharePoint.Security; using Microsoft.Office.Server; using Microsoft.Office.Server.Administration; using Microsoft.Office .Server .UserProfiles ; using System.DirectoryServices; using System.Web; namespace JsGasActivityLibrary1 { public partial class Activity1: SequenceActivity { publicstatic DependencyProperty UserTextProperty = System.Workflow.ComponentModel.DependencyProperty.Register("UserText", typeof(string), typeof(Activity1)); [ValidationOption(ValidationOption.Optional)] [Description("This is the description which appears in the Property Browser")] [Category("This is the category which will be displayed in the Property Browser")] [Browsable(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] publicstring UserText { get { return ((string)(base.GetValue(Activity1.UserTextProperty))); } set { base.SetValue(Activity1.UserTextProperty, value); } } publicstatic DependencyProperty StrOutProperty = System.Workflow.ComponentModel.DependencyProperty.Register("StrOut", typeof(string), typeof(Activity1)); [ValidationOption(ValidationOption.Optional)] [Description("This is the description which appears in the Property Browser")] [Category("This is the category which will be displayed in the Property Browser")] [Browsable(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] publicstring StrOut { get { return ((string)(base.GetValue(Activity1.StrOutProperty))); } set { base.SetValue(Activity1.StrOutProperty, value); } } public Activity1() { InitializeComponent(); } privatevoid codeActivity1_ExecuteCode(object sender, EventArgs e) { DirectoryEntry AD =new DirectoryEntry("WinNT://"+ Environment.MachineName +",computer"); DirectoryEntry NewUser = AD.Children.Find(UserText.Substring (UserText .IndexOf ("//")+1) , "user"); StrOut = NewUser.InvokeGet("FullName").ToString(); } } }
下面是给本机增加一个用户名TestUser1,密码#12345Abc,全名:我的用户,描述:Test User from .Net的代码片。