In Documnet library, we can not set item level permission by using Sharepoint Document Library Settings (unlike sharepoint List Settings). There is a very simple code snippet which does the same for us.
Code snippet
using (SPSite spSiteObje = new SPSite("http://SiteColName/Subsite"))
{
using (SPWeb spObjWeb = site.OpenWeb())
{
SPList spObjDocLib = web.Lists["MyDocLib"];
spObjDocLib.ReadSecurity = 2;
spObjDocLib.WriteSecurity = 2;
spObjDocLib.Update();
}
}
Wednesday, December 9, 2009
Set Item level permission in Sharepoint Document Library
Use ListViewWebPart to display listdata from different than current sharepoint site.
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace TestDashboard
{
[Guid("b732479d-6bcd-4dd9-97de-85f11bsdc5cb")]
public class TestDashboard : System.Web.UI.WebControls.WebParts.WebPart
{
public TestDashboard()
{
}
protected override void CreateChildControls()
{
base.CreateChildControls();
ListViewWebPart wp = new ListViewWebPart();
SPSite objSpSite = null;
using (objSpSite = new SPSite("http://SiteColName/SiteName/"))
{
objSpSite = new SPSite("http://SiteColName/SiteName/", objSpSite.SystemAccount.UserToken);
using (SPWeb spweb = objSpSite.OpenWeb())
{
SPList splist = spweb.Lists["ListName"];
wp.ListName = splist.ID.ToString("B").ToUpper();
wp.ViewGuid = splist.Views["All Items"].ID.ToString("B").ToUpper();
wp.ViewType = ViewType.Html;
wp.WebId = spweb.ID;
wp.SuppressWebPartChrome = true;
wp.GetDesignTimeHtml();
this.Controls.Add(wp);
}
}
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
EnsureChildControls();
}
}
}
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace TestDashboard
{
[Guid("b732479d-6bcd-4dd9-97de-85f11bsdc5cb")]
public class TestDashboard : System.Web.UI.WebControls.WebParts.WebPart
{
public TestDashboard()
{
}
protected override void CreateChildControls()
{
base.CreateChildControls();
ListViewWebPart wp = new ListViewWebPart();
SPSite objSpSite = null;
using (objSpSite = new SPSite("http://SiteColName/SiteName/"))
{
objSpSite = new SPSite("http://SiteColName/SiteName/", objSpSite.SystemAccount.UserToken);
using (SPWeb spweb = objSpSite.OpenWeb())
{
SPList splist = spweb.Lists["ListName"];
wp.ListName = splist.ID.ToString("B").ToUpper();
wp.ViewGuid = splist.Views["All Items"].ID.ToString("B").ToUpper();
wp.ViewType = ViewType.Html;
wp.WebId = spweb.ID;
wp.SuppressWebPartChrome = true;
wp.GetDesignTimeHtml();
this.Controls.Add(wp);
}
}
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
EnsureChildControls();
}
}
}
Wednesday, December 2, 2009
Customize EditForm.aspx, AllItems.aspx or any forms.
1. Goto Sharepoint designer.
2. Open desired site and then list in folder view.
3. Copy EditForm.aspx and paste it
4. Rename the newly copied EditForm.aspx ( MyEditForm.aspx)
5. In new MyEditForm.aspx go to code view.
6. Search for ListFormWebPart. (WebPartPages:ListFormWebPart)
7. Go to the properties of ListFormWebPart (Webpart properties)
8. Check the hidden check box under layouts section. (Layouts/Hidden)
9. THen,
10. Go to Insert menu.
11. Select Sharepoint Controls.
12. Add Custom List Form.
13. It will expose the whole webpart in a form of text boxes,lables and all HTML controls.
You can play with them by hide/show or whatever you want to achieve. Nice enough???
Note: By doing so, you will also able to add column values for Folder also. I mean, generally you can not add properties of Folder, unlike you can do for a list item or a Document. But this process will enable you to add properties of folder.
2. Open desired site and then list in folder view.
3. Copy EditForm.aspx and paste it
4. Rename the newly copied EditForm.aspx ( MyEditForm.aspx)
5. In new MyEditForm.aspx go to code view.
6. Search for ListFormWebPart. (WebPartPages:ListFormWebPart)
7. Go to the properties of ListFormWebPart (Webpart properties)
8. Check the hidden check box under layouts section. (Layouts/Hidden)
9. THen,
10. Go to Insert menu.
11. Select Sharepoint Controls.
12. Add Custom List Form.
13. It will expose the whole webpart in a form of text boxes,lables and all HTML controls.
You can play with them by hide/show or whatever you want to achieve. Nice enough???
Note: By doing so, you will also able to add column values for Folder also. I mean, generally you can not add properties of Folder, unlike you can do for a list item or a Document. But this process will enable you to add properties of folder.
Subscribe to:
Posts (Atom)