Wednesday, March 9, 2011
Sharepoint 2007 and 2010 boundaries and max limits
http://technet.microsoft.com/en-us/library/cc262787.aspx#Overview
http://mystepstones.wordpress.com/2007/06/04/more-sharepoint-2007-figures-numbers/
http://technet.microsoft.com/en-us/library/cc262787.aspx
Friday, January 14, 2011
Get/View Audit Entries for Document Library in sharepoint 2010
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite ElevatedSiteCollection = new SPSite("yoursite"))
{
using (SPWeb ElevatedSite = ElevatedSiteCollection.OpenWeb())
{
Console.Write(ElevatedSite.Site.Url); SPList list = ElevatedSite.Lists["TestDocuments"];
// ElevatedSite.Lists[new Guid(ListId)];
Console.Write(list.Audit.AuditFlags + "\n");
SPListItem item = list.Items.GetItemById(list.Items[0].ID);
Console.Write(item.Title); SPAuditQuery wssQuery;
SPAuditEntryCollection auditCol; wssQuery = new SPAuditQuery(ElevatedSiteCollection);
wssQuery.RestrictToListItem(item); auditCol = ElevatedSite.Audit.GetEntries(wssQuery);
foreach (SPAuditEntry entry in auditCol)
{
// Query audit log with elevated privileges.
Console.Write(entry.Occurred.ToLocalTime() + " : " + entry.Event + " by " + GetUserNameById(entry.UserId, ElevatedSite) + "\n");
}
}
}
});
Create a policy for Content type programmatically in Sharepoint 2010
using (SPSite siteCollection = new SPSite("suryasite"))
{
using (SPWeb web = siteCollection.OpenWeb())
{
string strFeatureID = "Microsoft.Office.RecordsManagement.PolicyFeatures.PolicyAudit";
SPList list = web.Lists["Test2"];
SPContentType listctype = list.ContentTypes["CustomTemplate1"];
//listctype.
// Microsoft.Office.RecordsManagement.PolicyFeatures.PolicyAudit
Policy policyAudit = Policy.GetPolicy(listctype);
if (policyAudit == null)
// if (!policyAudit.Equals("CustomTemplate1"))
{
Policy.CreatePolicy(listctype, null);
policyAudit = Policy.GetPolicy(listctype);
policyAudit.Name = "OPS Audit Policy";
policyAudit.Statement = "OPS Audit on Project Documents content type"; //string.Format("Audits Edit/Delete/Restore {0} items", Helper.PREFIX);
policyAudit.Description = policyAudit.Statement;
if (policyAudit.Items[strFeatureID] == null)
{
string strCustomData = " ";
policyAudit.Items.Add(strFeatureID, strCustomData);
}
}
}
}
Create/Get Documents from Document set programmatically in Sharepoint 2010
here i have one "Test Docs" library and it has some items which was created by using document set contenttype. when i click on on "Documentset item" it shows welcome page. i am trying to get documents which r in welcome page by using below code.
SPFolder folder = SPContext.Current.ListItem.Folder;
DocumentSet dset = DocumentSet.GetDocumentSet(folder);
SPListItem listitem = dset.Item;
foreach (SPFile item in listitem.Folder.Files)
{
}
Create DOcument set programmatically in sharepoint 2010
SPList WorkingDocslist = web.Lists["TestDocs"];
SPFolder folderToInsertIn = WorkingDocslist.RootFolder;
//Get the content type ID for the specified document set content type.
SPContentTypeId dsCtId = new SPContentTypeId();
Hashtable properties = new Hashtable();
properties.Add("projectid", projectID);
properties.Add("TaskID", taskID);
//Create the new Document Set object.
string strDocSetName = string.Empty;
dsCtId = WorkingDocslist.ContentTypes["Project Negotiations Package"].Id;
DocumentSet.Create(folderToInsertIn, strDocSetName , dsCtId, properties, true);
Thursday, December 16, 2010
See full error message in SharePoint 2010
you can see one more web.config file in under Layouts folder
change it to
customErrors mode="Off"
Friday, December 10, 2010
Sharepoint List Item Version History
if (docListItem != null)
{
// Create new DataTable.
DataTable dtHistory = new DataTable();
try
{
//starts History section
// Declare DataColumn and DataRow variables.
DataColumn LastModifiedBy;
DataColumn LastModifiedOn;
DataColumn Comments;
DataColumn Version;
DataRow row;
// Create new DataColumn, set DataType, ColumnName
// and add to DataTable.
//column.DataType = System.Type.GetType("System.Int32");
LastModifiedBy = new DataColumn();
LastModifiedBy.ColumnName = "LastModifiedBy";
dtHistory.Columns.Add(LastModifiedBy);
LastModifiedOn = new DataColumn();
LastModifiedOn.ColumnName = "LastModifiedOn";
dtHistory.Columns.Add(LastModifiedOn);
Comments = new DataColumn();
Comments.ColumnName = "Comments";
dtHistory.Columns.Add(Comments);
Version = new DataColumn();
Version.ColumnName = "Version";
dtHistory.Columns.Add(Version);
SPFieldUserValue ModifiedBy = new SPFieldUserValue(web, docListItem["Editor"].ToString());
row = dtHistory.NewRow();
row["LastModifiedBy"] = ModifiedBy.LookupValue;
row["LastModifiedOn"] = docListItem["Modified"];
if (docListItem["_CheckinComment"] != null) //Check In Comment
{
if (docListItem["_CheckinComment"].ToString().Length >= 3)
row["Comments"] = docListItem["_CheckinComment"].ToString().Remove(0, 3);
}
row["Version"] = docListItem["_UIVersionString"];
dtHistory.Rows.Add(row);
// it gets latest record
for (int i = 0; i < docListItem.File.Versions.Count; i++)
{
row = dtHistory.NewRow();
row["LastModifiedBy"] = docListItem.File.Versions[i].CreatedBy.Name;
row["LastModifiedOn"] = docListItem.File.Versions[i].Created.ToLocalTime().ToString();
row["Comments"] = docListItem.File.Versions[i].CheckInComment;
//Response.Write("2nd loop: " + docListItem.File.Versions[i].CheckInComment);
row["Version"] = docListItem.File.Versions[i].VersionLabel;
dtHistory.Rows.Add(row);
}
//grdHistory.DataSource = docListItem.Versions;
dtHistory.DefaultView.Sort = "Version Desc";
grdHistory.DataSource = dtHistory;
grdHistory.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
dtHistory.Dispose();
}
//Activity log section
SPAuditQuery wssQuery;
SPAuditEntryCollection auditCol;
wssQuery = new SPAuditQuery(ElevatedWeb.Site);
wssQuery.RestrictToListItem(docListItem = documentListCollection[0]);
auditCol = ElevatedWeb.Site.Audit.GetEntries(wssQuery);
DataTable dtActivity = new DataTable("ActivityLog");
DataColumn colLog = new DataColumn();
colLog.ColumnName = "Log";
DataRow drow;
dtActivity.Columns.Add(colLog);
foreach (SPAuditEntry entry in auditCol)
{
if (entry.Event == SPAuditEventType.CheckOut || entry.Event == SPAuditEventType.CheckIn || entry.Event == SPAuditEventType.FileFragmentWrite)
{
drow = dtActivity.NewRow();
// if (ParseVersionNumber(entry.EventData) != "N/A")
// {
drow[0] = entry.Occurred.ToLocalTime() + " : " + entry.Event + " by " + GetUserNameById(entry.UserId, site);
dtActivity.Rows.Add(drow);
//}
}
}
grdActivitylog.DataSource = dtActivity;
grdActivitylog.DataBind();
dtActivity.Dispose();
}
}
Add/Delete/Update Quicklaunch Navigation Programmatically in Sharepoint
SPSite site = new SPSite("sitename");
SPWeb Web = site.OpenWeb();
SPNavigationNodeCollection nodes = Web.Navigation.QuickLaunch;
SPNavigationNode NavNodeWorkingDoc = null;
SPNavigationNode NavNodePicLib = null;
SPNavigationNode NavNodeRefLib = null;
SPNavigationNode navNodeFinalDoc = null;
SPNavigationNode navNodePublished = null;
SPNavigationNode navNodeDisclosed = null;
foreach (SPNavigationNode node in nodes)
{
if (node.Title.Equals("Documents")) //Documents
{
foreach (SPNavigationNode childnode in node.Children)
{
if (childnode.Title.Equals("Documents"))
{
childnode.Delete();
//childnode.Url = "url name"
}
else if (childnode.Title.Equals("Project Documents"))
{
NavNodeWorkingDoc = childnode;
NavNodeWorkingDoc.Title = "Working Documents";
NavNodeWorkingDoc.Update();
}
else if (childnode.Title.Equals("Picture Library"))
{
NavNodePicLib = childnode;
NavNodePicLib.Title = "Picture Gallery";
NavNodePicLib.Update();
}
else if (childnode.Title.Equals("Reference Library"))
{
NavNodeRefLib = childnode;
}
}
node.Children.Add(navNodeFinalDoc, NavNodeRefLib);
node.Children.Add(navNodePublished, navNodeFinalDoc);
node.Children.Add(navNodeDisclosed, navNodePublished);
}
}
Subscribe to:
Posts (Atom)
