public static void CreatePermissions(SPWeb theWeb, string loginName, string roleName, string permissionLevel)
{
try
{
theWeb = new SPSite(theWeb.Site.ID).OpenWeb(theWeb.ID);
theWeb.AllowUnsafeUpdates = true;
SPRoleAssignment roleAssignment = new SPRoleAssignment(loginName, "", roleName, "");
SPRoleDefinition RoleDefinition = theWeb.RoleDefinitions[permissionLevel];
if (!roleAssignment.RoleDefinitionBindings.Contains(RoleDefinition))
roleAssignment.RoleDefinitionBindings.Add(RoleDefinition);
//Check inheritance
if (!theWeb.HasUniqueRoleAssignments)
{
theWeb.BreakRoleInheritance(false);
}
theWeb.RoleAssignments.Add(roleAssignment);
//If user already exists - update its display name
try
{
SPUser user = null;
user = theWeb.Users[loginName];
user.Name = roleName;
user.Update();
}
catch { }
theWeb.Update();
}
catch (Exception exc)
{
}
}
public static void CreatePermissions(SPWeb theWeb, SPListItem ListItem, string loginName, string roleName, string permissionLevel)
{
try
{
theWeb = new SPSite(theWeb.Site.ID).OpenWeb(theWeb.ID);
theWeb.AllowUnsafeUpdates = true;
ListItem = theWeb.Lists[ListItem.ParentList.ID].GetItemById(ListItem.ID);
SPRoleAssignment roleAssignment = new SPRoleAssignment(loginName, "", roleName, "");
SPRoleDefinition RoleDefinition = theWeb.RoleDefinitions[permissionLevel];
if (!roleAssignment.RoleDefinitionBindings.Contains(RoleDefinition))
roleAssignment.RoleDefinitionBindings.Add(RoleDefinition);
//Check inheritance
if (!ListItem.HasUniqueRoleAssignments)
{
ListItem.BreakRoleInheritance(false);
}
ListItem.RoleAssignments.Add(roleAssignment);
ListItem.Update();
}
catch (Exception exc)
{
}
}
public static void CreatePermissions(SPWeb theWeb, SPList list, string loginName, string roleName, string permissionLevel)
{
try
{
theWeb = Utilities.Refresh(theWeb);
SPRoleAssignment roleAssignment = new SPRoleAssignment(loginName, "", roleName, "");
SPRoleDefinition RoleDefinition = theWeb.RoleDefinitions[permissionLevel];
if (!roleAssignment.RoleDefinitionBindings.Contains(RoleDefinition))
roleAssignment.RoleDefinitionBindings.Add(RoleDefinition);
//Check inheritance
if (!list.HasUniqueRoleAssignments)
{
list.BreakRoleInheritance(false);
}
list.RoleAssignments.Add(roleAssignment);
list.Update();
}
catch (Exception ex)
{
}
}
大家試試看吧~~
December 22
最近有人問我說怎樣寫一支將使用者加入 Active Directory 中... 因為 MOSS 要使用到,但是其實說穿了不管是用 Web AP 或是 WebPart 甚至是 SmartPart 中的 User Control 其實 Code 都大同小異,那我將下面的 Code 分享一下ㄅㄟ
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 System.DirectoryServices;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String RootDSE;
string _FirstName = "";
string _LastName = "";
string _Account = "";
string _Password = "";
string _Description = "";
string _Telephone = "";
string _mailAddress = "";
string _Company = "";
string _Department = "";
string _City = "";
string _PostCode = "";
string _CompanyAddress = "";
_FirstName = "Ho";
_LastName = "WeiShoun";
_Account = "weishoun";
_Password = "pass@word1";
_Description = "ADSI Testing Account";
_Telephone = "0916905123";
_mailAddress = "weishoun@rstn.com";
_Company = "RSTN";
_Department = "Office System";
_City = "Taipei";
_PostCode = "106";
_CompanyAddress = "Taiwan Taipei Duhwa Sourth Rd. Room 1210";
try
{
DirectorySearcher DSESearcher = new DirectorySearcher();
RootDSE = DSESearcher.SearchRoot.Path;
RootDSE = RootDSE.Insert(7, "CN=Users,");
DirectoryEntry ITProDE = new DirectoryEntry(RootDSE);
DirectoryEntries ITProEntries = ITProDE.Children;
DirectoryEntry ITProDirectoryEntry = ITProEntries.Add("CN=" + _Account, "user");
ITProDirectoryEntry.CommitChanges();
ITProDirectoryEntry.CommitChanges();
//姓氏
ITProDirectoryEntry.Invoke("Put", new Object[] { "sn", _FirstName });
//名字
ITProDirectoryEntry.Invoke("Put", new Object[] { "givenName", _LastName });
//帳號
ITProDirectoryEntry.Invoke("Put", new Object[] { "samAccountName", _Account });
ITProDirectoryEntry.Invoke("Put", new Object[] { "userPrincipalName", _Account });
//密碼
ITProDirectoryEntry.Invoke("SetPassword", new Object[] { _Password });
//==============================================================================
//
// ADS_USER_FLAG_ENUM enumeration defines the flags used for setting user
// properties in the directory.
//
//==============================================================================
//ADS_UF_SCRIPT = 1, // 0x1
//ADS_UF_ACCOUNTDISABLE = 2, // 0x2
//ADS_UF_HOMEDIR_REQUIRED = 8, // 0x8
//ADS_UF_LOCKOUT = 16, // 0x10
//ADS_UF_PASSWD_NOTREQD = 32, // 0x20
//ADS_UF_PASSWD_CANT_CHANGE = 64, // 0x40
//ADS_UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED = 128, // 0x80
//ADS_UF_TEMP_DUPLICATE_ACCOUNT = 256, // 0x100
//ADS_UF_NORMAL_ACCOUNT = 512, // 0x200
//ADS_UF_INTERDOMAIN_TRUST_ACCOUNT = 2048, // 0x800
//ADS_UF_WORKSTATION_TRUST_ACCOUNT = 4096, // 0x1000
//ADS_UF_SERVER_TRUST_ACCOUNT = 8192, // 0x2000
//ADS_UF_DONT_EXPIRE_PASSWD = 65536, // 0x10000
//ADS_UF_MNS_LOGON_ACCOUNT = 131072, // 0x20000
//ADS_UF_SMARTCARD_REQUIRED = 262144, // 0x40000
//ADS_UF_TRUSTED_FOR_DELEGATION = 524288, // 0x80000
//ADS_UF_NOT_DELEGATED = 1048576, // 0x100000
//ADS_UF_USE_DES_KEY_ONLY = 2097152, // 0x200000
//ADS_UF_DONT_REQUIRE_PREAUTH = 4194304, // 0x400000
//ADS_UF_PASSWORD_EXPIRED = 8388608, // 0x800000
//ADS_UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION = 16777216 // 0x1000000
//==============================================================================
ITProDirectoryEntry.Invoke("Put", new Object[] { "userAccountControl", 0x10000 });
ITProDirectoryEntry.CommitChanges();
//==============================================================================
//
// Setting user properties in the directory.
//
//==============================================================================
//顯示名稱
ITProDirectoryEntry.Properties["displayName"].Add(_FirstName + "" + _LastName);
//描述
ITProDirectoryEntry.Properties["Description"].Add( _Description);
//電話號碼: Format: (02)2777-1556
ITProDirectoryEntry.Properties["telephoneNumber"].Add(_Telephone);
//電子郵件: Format: weishoun@rstn.com
ITProDirectoryEntry.Properties["mail"].Add(_mailAddress);
//公司: RSTN
ITProDirectoryEntry.Properties["company"].Add(_Company);
//部門: 資訊
ITProDirectoryEntry.Properties["department"].Add(_Department);
//市: 台北市/ 高雄市
ITProDirectoryEntry.Properties["st"].Add(_City);
//郵遞區號: 106
ITProDirectoryEntry.Properties["postalCode"].Add(_PostCode);
//住址: 敦化南路一段212號...
ITProDirectoryEntry.Properties["streetAddress"].Add(_CompanyAddress);
//==============================================================================
ITProDirectoryEntry.CommitChanges();
DSESearcher.Dispose();
ITProDirectoryEntry.Dispose();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
December 17
You Can Download this Installation File From this...
December 13
Microsoft Office Share Point Server Sp1 Release:
Hotfix Item:
Hotfix 926284: List view web part not retained saving template
• Hotfix 938888: Edit document fails/IE Crash side by side Office
• Hotfix 938663: Timer jobs delayed one hour because of DST
• Hotfix 936867: Inherit permissions causes destructive error (lose permissions to site)
• Hotfix 930807: Cannot open WSS alerts in Outlook cached mode
• Hotfix 932816: Workflow not continue after Pause For Duration
• Hotfix 936867: Export fails with FatalError User cannot be found
• Hotfix 934790: peoplepicker-searchadcustomquery filter broken
• Hotfix 926284: List view web part not retained saving template
• Hotfix 938888: Edit document fails/IE Crash side by side Office
• Hotfix 932091: Hotfix packages break customer deployments primarily
• Hotfix 936867: Inherit perms causes destructive error
Below is the excerpt from http://blogs.technet.com/wbaer/archive/2007/03/25/understanding-webtemp-xml.aspx
WEBTEMP.xml
Products: Microsoft Office SharePoint Server 2007/Windows SharePoint Services 3.0
Includes: Team Site, Blank Site, Document Workspace, Basic Meeting Workspace, Blank Meeting Workspace, Decision Meeting Workspace, Social Meeting Workspace, Multipage Meeting Workspace, Central Admin Site, Wiki Site, and Blog templates.
webtempsrch.xml
Products: Microsoft Office SharePoint Server 2007
Includes: Search Center template.
webtempsps.xml
Products: Microsoft Office SharePoint Server 2007
Includes: SharePoint Portal Server Site, SharePoint Portal Server Personal Space, Personalization Site, Contents area Template, Topic area Template, News Site, Publishing Site, Press Releases Site, Publishing Site with Workflow, Site Directory, Community area Template, Report Center, Collaboration Portal, Search Center with Tabs, Profiles, Publishing Portal, My Site Host templates.
webtempoffile.xml
Products: Microsoft Office SharePoint Server 2007
Includes: Records Center template.
webtempbdr.<local>.xml
Products: Microsoft Office SharePoint Server 2007
Includes: Document Center template.
webtemposrv.xml
Products: Microsoft Office SharePoint Server 2007
Includes: Shared Services Administration Site template.
Configuration Attributes:
- <Title> Template title text displayed in the Template Selection user interface.
- <Description> Description of the purpose and features of the requested template displayed in the Template Selection user interface.
- <ImageUrl> Provides the virtual path to the preview image displayed in the Template Selection user interface.
- <DisplayCategory> Defines the category where the template should be made available for selection in the Template Selection user interface.
- <RootWebOnly> Defines the usage scenario in which this template can be applied.
- <ProvisionAssembly> Provides the fundamental publishing infrastructure in Microsoft Office SharePoint Server 2007.
- <ProvisionClass> Defines the class associated with the <ProvisionAssembly> attribute.
- <ProvisionData> Provides the virtual path to the associated Web manifest (%commonprogramfiles%\Microsoft Shared\Web Server Extensions\12\TEMPLATE\SiteTemplates\WebManifest\portalwebmanifest.xml)
- <VisibilityFeatureDependency> Feature dependency associated with the template that provides its visibility.
1.
Open the folder: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\GLOBAL\XML
Apparently there is now a “global” folder for site definition files, I am still trying to understand the mapping of things from SPS 2003 and MOSS 2007.
2.
Find and open the file named “ONET.XML” in your favorite XML/text editor (good old notepad for me please)
3.
On line 693 you will find this line of XML:
<Else><HTML><![CDATA[<A onfocus="OnLink(this)" HREF="]]></HTML>
Changing this line to as shown below will change the behavior of the textual links to open in a new window
<Else><HTML><![CDATA[<A onfocus="OnLink(this)" target="_new" HREF="]]></HTML>
4.
On line 838 you will find this similar line of XML:
<Else><HTML><![CDATA[<A TABINDEX=-1 HREF="]]></HTML>
Changing this line to as shown below will change the behavior of the image icon links to open in a new window
<Else><HTML><![CDATA[<A TABINDEX=-1 target="_new" HREF="]]></HTML>
5.
Save changes do an IISRESET and you should be good to go. Of course if you are in a medium or large farm scenario you will need to perform these steps for each front-end web server
SharePoint, for all it's glory, can be frustrating; just ask anyone who's developed on the platform for longer than 20 minutes. Sooner or later an error message telling you there was an "Unknown Error" will show up and you'll have to hustle over to the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS directory to try and locate the line where the mysterious error took place.
One way to help ease that frustration is to enable debugging in the web.config file of your web application.
Change this line:
<SharePoint>
<SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">
</SharePoint>
To this:
<SharePoint>
<SafeMode MaxControls="200" CallStack="true" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">
</SharePoint>
And:
<system.web>
<customErrors mode="Off" />
</system.web>
A Provider can be any search engine, external (Google) or internal (MOSS).
1. Click on the arrow next to the magnifying glass in IE and select "Find More Providers…".
2. In the Create Your Own" section on the page you are redirected to, enter the URL of your MOSS search resutls page, ensuring that the "k" querystring parameter's value is "TEST".
http://moss.neudesic.com/searchcenter/Pages/Results.aspx?k=TEST&s=All%20Sites
3. Name the Provider something meaningful and click "Install".
4. Click the arrow next to the magnifying glass again and you will see the Provider you just added.
5. Optionally, you may want this Provider to be the default, which can be accomplished by selecting "Change Search Defaults".
How'd they do that?
IE7 uses A9's OpenSearch standard to import Providers.
Here's a sample OpenSearch description:
<?xml version="1.0" encoding="UTF-8" ?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>Neudesic MOSS Search</ShortName>
<Description>Neudesic MOSS Search provider</Description>
<InputEncoding>UTF-8</InputEncoding>
<Url type="text/html" template="http://moss.neudesic.com/searchcenter/Pages/Results.aspx?k={searchTerms}&s=All%20Sites" />
</OpenSearchDescription>
Note that this can also be done from the registry.
Adding the same functionality via the Registry is fairly simple. Just add the following registry key:
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\SearchScopes\MOSS]
@="Neudesic MOSS"
"DisplayName"="Neudesic MOSS"
"Url"="http://moss.neudesic.com/SearchCenter/Pages/Results.aspx?k={searchTerms}&s=All%20Sites"
Don't forget to replace the "Url" string with your own MOSS search results page