Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data;
- using System.Web.UI.WebControls;
- using System.Web.UI;
- using System.Collections.Generic;
- using System.ComponentModel;
- using Microsoft.SharePoint;
- using Microsoft.SharePoint.WebPartPages;
- using Microsoft.SharePoint.Administration;
- using System.Collections;
- namespace Custom_Webparts.Stab_List_Summary
- {
- [ToolboxItemAttribute(false)]
- public partial class Stab_List_Summary : WebPart
- {
- // Uncomment the following SecurityPermission attribute only when doing Performance Profiling on a farm solution
- // using the Instrumentation method, and then remove the SecurityPermission attribute when the code is ready
- // for production. Because the SecurityPermission attribute bypasses the security check for callers of
- // your constructor, it's not recommended for production purposes.
- // [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]
- public DCS_Stab_List_Summary()
- {
- }
- protected override void OnInit(EventArgs e)
- {
- base.OnInit(e);
- InitializeControl();
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- using (SPSite site = new SPSite("http://sitename")) // This URL needs to be changed to appropriate URL.
- {
- using (SPWeb web = site.OpenWeb())
- {
- // refer to the Stab List
- SPList olist = web.Lists["Stab List"]; // "Stab List" needs to be changed to appropriate list name
- //new XSLT webpart
- XsltListViewWebPart webpart = new XsltListViewWebPart();
- //custom XSLT Listview webpart properties
- webpart.ListName = olist.ID.ToString("B").ToUpper();
- webpart.AllowEdit = true;
- webpart.AllowConnect = true;
- webpart.AllowZoneChange = true;
- //Refer views for different user
- SPView oTView = olist.Views["Summary T"];
- SPView oEView = olist.Views["Summary E"];
- SPView oNormalView = olist.Views["Summary"];
- //getthe logged in user name
- SPUser oUser = SPContext.Current.Web.CurrentUser;
- //If logged in user is T_sp, then apply appropriate view
- if (oUser.Name.Contains("T_sp")) // t_sp
- {
- webpart.ViewGuid = oTView.ID.ToString("B");
- }
- else if (oUser.Name.Contains("E_sp")) // e_sp;
- {
- webpart.ViewGuid = oEView.ID.ToString("B");
- }
- // for other supply default view
- else
- {
- webpart.ViewGuid = oNormalView.ID.ToString("B");
- }
- this.Controls.Add(webpart);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement