lunedì 22 agosto 2011

Tutte le document library dei siti e dei sotto siti..

Modificando un pò il metodo "RenderContacts" si possono ricercare e modificare anche le proprietà delle liste (giocando un pò con il codice 1 e il codice 2).

Code 1:

protected override void Render(HtmlTextWriter output)
{
RenderContacts(output);
}
private void RenderContacts(HtmlTextWriter output)
{
SPWeb web = SPContext.Current.Web;
SPQuery oQuery = new SPQuery();
SPListItemCollection Items;
oQuery.Query = String.Format(""); //Put your caml query

SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(this.Page.Request.Url.ToString()))
{
using (SPWeb oWeb = site.OpenWeb())
{
SPWebCollection subSites = site.AllWebs;
for (int i = 0; i < subSites.Count; i++)
{
SPListCollection lists = subSites[i].Lists;
foreach (SPList List in lists)
{
if (List.BaseType == SPBaseType.DocumentLibrary && List.BaseTemplate == SPListTemplateType.DocumentLibrary)
{
try
{
Items = List.GetItems(oQuery);
foreach (SPListItem item in Items)
{
output.write(item["Document Name"].ToString());
}
foreach (SPFolder fold in List.RootFolder.SubFolders)
{
oQuery.Folder = fold;
oQuery.ViewAttributes = "Scope=\"Recursive\"";
Items = List.GetItems(oQuery);
foreach (SPListItem item in Items)
{
output.write(item["Document Name"].ToString());
}
}
}
catch (Exception exe)
{
}
}
}
}
}
}
});

}
protected override void CreateChildControls()
{
base.CreateChildControls();
}

Code 2:

1) Abilitare Content Management on a document library :

// web is instance of SPWeb
SPList docList = web.Lists["Custom List"];
// set the bool property
docList.ContentTypesEnabled = true;
// now you are ready to add your custom content types
// first get instance to your custom content type
SPContentType customContentType = web.Site.RootWeb.ContentTypes["Custom Content Type"];
docList.ContentTypes.Add(customContentType);
// and never forget this
docList.Update();
2) Abilitare Versioning on documents :

// get reference to the document library in which you want to enable versioning
// web is instance of SPWeb
SPList docList = web.Lists["Custom List"];
// enable both major and minor versioning flags like this (if you want both major and minor versioning)
docList.EnableVersioning = true;
docList.EnableMinorVersions = true;

// and do not forget this
docList.Update();
3) Abilitare Content Approval on documents

// get reference to the document library in which you want to enable content approval
// web is instance of SPWeb
SPList docList = web.Lists["Custom List"];
// enable content approval like this
docList.EnableModeration = true;
// and do not forget this
docList.Update();
4) Forzare Checkout of Document before edit :

// get reference to the document library in which you want to enable versioning
// web is instance of SPWeb
SPList docList = web.Lists["Custom List"];
// enable force checkout before edit like this
docList.ForceCheckout = true;
// and do not forget this
docList.Update();



Nessun commento:

Posta un commento