Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using System.Web.UI.WebControls;
  4. using System.Web.UI;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using Microsoft.SharePoint;
  8. using Microsoft.SharePoint.WebPartPages;
  9. using Microsoft.SharePoint.Administration;
  10. using System.Collections;
  11.  
  12. namespace Custom_Webparts.Stab_List_Summary
  13. {
  14. [ToolboxItemAttribute(false)]
  15. public partial class Stab_List_Summary : WebPart
  16. {
  17. // Uncomment the following SecurityPermission attribute only when doing Performance Profiling on a farm solution
  18. // using the Instrumentation method, and then remove the SecurityPermission attribute when the code is ready
  19. // for production. Because the SecurityPermission attribute bypasses the security check for callers of
  20. // your constructor, it's not recommended for production purposes.
  21. // [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]
  22. public DCS_Stab_List_Summary()
  23. {
  24. }
  25.  
  26. protected override void OnInit(EventArgs e)
  27. {
  28. base.OnInit(e);
  29. InitializeControl();
  30. }
  31.  
  32. protected void Page_Load(object sender, EventArgs e)
  33. {
  34. using (SPSite site = new SPSite("http://sitename")) // This URL needs to be changed to appropriate URL.
  35. {
  36. using (SPWeb web = site.OpenWeb())
  37. {
  38. // refer to the Stab List
  39. SPList olist = web.Lists["Stab List"]; // "Stab List" needs to be changed to appropriate list name
  40.  
  41. //new XSLT webpart
  42. XsltListViewWebPart webpart = new XsltListViewWebPart();
  43.  
  44. //custom XSLT Listview webpart properties
  45. webpart.ListName = olist.ID.ToString("B").ToUpper();
  46. webpart.AllowEdit = true;
  47. webpart.AllowConnect = true;
  48. webpart.AllowZoneChange = true;
  49.  
  50. //Refer views for different user
  51. SPView oTView = olist.Views["Summary T"];
  52. SPView oEView = olist.Views["Summary E"];
  53. SPView oNormalView = olist.Views["Summary"];
  54.  
  55. //getthe logged in user name
  56. SPUser oUser = SPContext.Current.Web.CurrentUser;
  57.  
  58.  
  59. //If logged in user is T_sp, then apply appropriate view
  60. if (oUser.Name.Contains("T_sp")) // t_sp
  61. {
  62. webpart.ViewGuid = oTView.ID.ToString("B");
  63. }
  64. else if (oUser.Name.Contains("E_sp")) // e_sp;
  65. {
  66. webpart.ViewGuid = oEView.ID.ToString("B");
  67. }
  68. // for other supply default view
  69. else
  70. {
  71. webpart.ViewGuid = oNormalView.ID.ToString("B");
  72. }
  73.  
  74. this.Controls.Add(webpart);
  75. }
  76. }
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement