martes, 11 de agosto de 2009

Crear Usuario en site en Sharepoint con aspnet

Cuando intente Crear un site en sharepoint rapido pense en los sharepoint web service
http://msdn.microsoft.com/en-us/library/dd878586.aspx
y puede usar el web service
http://site/_vti_bin/meetings.asmx con el siguiente codigo:

Dim cc As New System.Net.NetworkCredential
cc.UserName = "administrator"
cc.Domain = "test"
cc.Password = "test"

Dim WMService As New MeetingWebService.Meetings()
WMService.Credentials = cc
Dim tz As New MeetingWebService.TimeZoneInf()

Dim xnode As Xml.XmlNode = WMService.CreateWorkspace("pruebasts1", "STS#0", System.UInt32.Parse("1033"), tz)

sin embargo este codigo tiene muchas desventajas por que los web service no tiene todas las caracteristicas para automatizar el sharepoint.

lo que tiene que hacer es lo siguiente:
paso 1
buscar el un dll de sharepoint y referenciarlo a su proyecto la cual se encuentra en:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.SharePoint.dll

paso 2
codigo para crear el sitio

//crea sitio en sharepoint
using (SPSite oSiteCollection = new SPSite("http://test"))
{
SPWebCollection collWebsites = oSiteCollection.AllWebs;
System.UInt32 lcid = new System.UInt32();
lcid = Convert.ToUInt32("1033");
SPWeb oWebsite = collWebsites.Add("site1", usuario, "Description xx", lcid, "STS#0", true, false);
}
//fin crea sitio en sharepoint

//crea el grupo de permisos
using (SPSite oSiteCollection = new SPSite("http://test"))
{
using (SPWeb oWebsite = oSiteCollection.OpenWeb("site-" + usuario))
{
string usuario="prueba";
string groupName1 = usuario + "-Contribuidor";
oWebsite.SiteUsers.Add("test\\" + usuario, "", usuario, "user:" + usuario);
SPUser ownerUser = oWebsite.SiteUsers["test\\" + usuario];
oWebsite.SiteGroups.Add(groupName1, ownerUser, ownerUser, "contrubuidor");
oWebsite.AssociatedGroups.Add(oWebsite.SiteGroups[groupName1]);
SPRoleDefinitionCollection roleDefinitions = oWebsite.RoleDefinitions;
SPRoleAssignmentCollection roleAssignments = oWebsite.RoleAssignments;
SPPrincipal author = oWebsite.SiteGroups[groupName1] as SPPrincipal;
SPRoleAssignment assignment = new SPRoleAssignment(author);
SPRoleDefinitionBindingCollection definitions = assignment.RoleDefinitionBindings;
//Contribute - Full Control
definitions.Add(roleDefinitions["Contribute"]);
roleAssignments.Add(assignment);
}
}
//fin del grupo de permisos

//crea las librerias
using (SPSite oSiteCollection = new SPSite("http://test"))
{
using (SPWeb oWebsite = oSiteCollection.OpenWeb("site-" + usuario))
{
oWebsite.Lists.Add("documentos", "documentos de " + usuario, SPListTemplateType.DocumentLibrary);
SPList newList = oWebsite.Lists["documentos"];
newList.OnQuickLaunch = true;
newList.Update();

oWebsite.Lists.Add("Fotos", "fotos de" + usuario, SPListTemplateType.PictureLibrary);
SPList newfotos = oWebsite.Lists["Fotos"];
newfotos.OnQuickLaunch = true;
newfotos.Update();
}
}
//fin de las librerias


si quiere hacerlo aun mas poderoso miren este articulo:
SharePoint Security and .NET Impersonation
http://www.15seconds.com/issue/040511.htm


Algunas otros templates para crear site.
STS#0 Team site
STS#1 Blank Site
STS#2 Document Workspace
MPS#0 Basic Meeting Workspace
MPS#1 Blank Meeting Workspace
MPS#2 Decision Meeting Workspace
MPS#3 Social Meeting Workspace
MPS#4 Multipage Meeting Workspace
WIKI#0 Wiki
BLOG#0 Blog
BDR#0 Document Center
OFFILE#0 Record Center 0
OFFILE#1 Record Center 1
OSRV#0 Shared Services Administration
SPSPERS#0 SP Portal Personal Space
SPSMSITE#0 Personalization Site
SPSTOC# COntents Area Template
SPSTOPIC#0 Topic Area Template
SPSNEWS#0 News Site
CMSPUBLISHING#0 Publishing Site 0
BLANKINTERNET#0 Publishing Site 1
BLANKINTERNET#2 Publishing Site with Workflow
SPSNHOME#0 News Site 2
SPSSITES#0 Site Directory
SPSCOMMU#0 Community Area Template
SPSREPORTCENTER#0 Report Center
SPSPORTAL#0 Collaboration Portal
SRCHCEN#0 Search Center with Tabs
PROFILES#0 Profiles
BLANKINTERNETCONTAINER#0 Publishing Portal
SPSMSITEHOST#0 My Site Host
SRCHCENTERLITE#0 Search Center 0
SRCHCENTERLITE#1 Search Center 1

1 comentario:

adriakuma dijo...

Gracias por la referencia, la utilizare a ver que pasa.