How to force my Web part to run regardless of users permissions

I have created the following custom permission , which will allow users to Create items without being able to view,edit them:-
$spweb=Get-SPWeb -Identity "http://vstg01";
$spRoleDefinition = New-Object Microsoft.SharePoint.SPRoleDefinition;
$spRoleDefinition.Name = "Submit only";
$spRoleDefinition.Description = "Can submit/add forms/files/items into library or list but cannot view/edit them.";
$spRoleDefinition.BasePermissions = "AddListItems, ViewPages, ViewFormPages, Open";
$spweb.RoleDefinitions.Add($spRoleDefinition);
$spweb.Dispose();
then inside my "Issue Tracking List" i stop inheriting permission from team site , and i define the following permission for all users:-
now users can add items and they can not view them ,, which is perfect :).
But now i wanted to add a custom web part to my Create form which will hide certain fields if the user is not within specific group ,the web part looks as follow:-
protected override void OnInit(EventArgs e)
base.OnInit(e);
InitializeControl();
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
using (SPWeb web = site.OpenWeb())
web.AllowUnsafeUpdates = true;
SPGroup group = web.Groups["Intranet Visitors"];
bool isUser = web.IsCurrentUserMemberOfGroup(group.ID);
if (!isUser)
SPList myList = web.Lists.TryGetList("Issue List");
SPField titleField = myList.Fields.GetField("Category");
titleField.Hidden = true;
titleField.ShowInEditForm = false;
titleField.ShowInNewForm = false;
titleField.ShowInDisplayForm = false;
titleField.Update();
myList.Update();
// web.AllowUnsafeUpdates = false;
else
SPList myList = web.Lists.TryGetList("Issue List");
SPField titleField = myList.Fields.GetField("Title");
titleField.Hidden = false;
titleField.Update();
myList.Update();
// //web.AllowUnsafeUpdates = false;
web.AllowUnsafeUpdates = false;
then i deploy the web part and i add it to the Create form. but after doing so user are not able to create items and they will get the following error:-
Sorry this site has not been shared with you
so can anyone advice how to force my web part to run , without checking the users permissions or with minimal permssions ?

in this case, use the elevated privileges to read/add/edit items with elevated privileges with below code.
but make sure the page which you add this web part have at least read access to all user.
SPSecurity.RunWithElevatedPrivileges(delegate()
using (SPSite site = new SPSite(web.Site.ID))
// implementation details omitted
More: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx
Bistesh
Ok after adding :-
SPSecurity.RunWithElevatedPrivileges(delegate()
users with the following permissions can create items:-
"AddListItems, ViewPages, ViewFormPages, Open";
and they can not edit/read them, which is great. but i am facing a caching problem , because if user is inside the "Intranet visitor" he will be able to see Category field as mentioned in my code, but if i remove him from the "Intranet Visitor"
he still can see the field,, although in the web part i specify not to display the Category column if the user is not inside the "Intranet visitor " group... here is my current code:-
protected override void OnInit(EventArgs e)
base.OnInit(e);
InitializeControl();
SPSecurity.RunWithElevatedPrivileges(delegate()
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
using (SPWeb web = site.OpenWeb())
web.AllowUnsafeUpdates = true;
SPGroup group = web.Groups["Intranet Visitor"];
bool isUser = web.IsCurrentUserMemberOfGroup(group.ID);
if (!isUser)
SPList myList = web.Lists.TryGetList("Risk & Issue Management");
SPField titleField = myList.Fields.GetField("Category");
titleField.Hidden = true;
titleField.ShowInEditForm = false;
titleField.ShowInNewForm = false;
titleField.ShowInDisplayForm = false;
titleField.Update();
myList.Update();
// web.AllowUnsafeUpdates = false;
else
SPList myList = web.Lists.TryGetList("Risk & Issue Management");
SPField titleField = myList.Fields.GetField("Category");
titleField.Hidden = false;
titleField.ShowInEditForm = true;
titleField.ShowInNewForm = true;
titleField.ShowInDisplayForm = true;
titleField.Update();
myList.Update();
web.AllowUnsafeUpdates = false;
so can you advice please ? is this a caching problem, or once the user add at-least single item he will be able to see all columns ?

Similar Messages

  • How to make the web part and web part zone smaller?

    Hello Community
        On WS2012 running SharePoint 2013 Server when you edit a page
    the web part zone is big and when you add the web part the web part 
    is big also.
        So the question is how to you make web parts and web part zone
    smaller?
        Thank you
        Shabeaut

    Hi,
    According to your description, my understanding is that you want to make the web part zone and web part smaller.
    When you edit a page, you could change the height and width of the web part in Edit Web Part -> Appearance by typing in the Height and Width field. The size of the web part zone changes with the web part.
    Best Regards,
    Dean Wang
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • How do I add web part in the event receiver after the site is provisioned in SP 2010?

    How do I add web part in the event receiver after the site is provisioned in SP 2010?

    You try the below steps:
    1. Use long operation to provision the site, so that it does not time out in process.
    2. After provisioning, you can add a page or add the web part directly to landing page of site.
    For each of the above steps you can find the sample code pieces.
    if you couldn't get that, let me know. I will share with you.
    Thanks, Ashish If my response has helped you, please mark as answer.

  • How to List view web part to display document library for only users with access permission

    Hi
    I am trying to accomplish this requirement but I don't know if that is possible or how to get there.  Any suggestion or advice are helpful.
    On a site collection, I have several document libraries,  with each library have unique permission to a few user or SharePoint group.
    I want to create a web part page and make that the site home page.  On this web part page, I want to create a Content Search Web Part to list the content of the document library that the logged on users have permission to see. 
    Is this possible with CSWP or is there anything easier or if it is not possible at all,  please advise.
    Thanks
    Swanl

    Hi ,
    Based on your description, my understanding is that you want to create a Content Search Web Part to list the documents that the logged on users have access permission.
    It is feasible with CSWP, you can follow the below step:
    Edit Content Search Web Part->Change query-> Select a query: Items matching a content type (System); Restrict by app: Current site collection; Restrict by content type: Document.
    Best Regards,
    Lisa Chen
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet
    Subscriber Support, contact [email protected]

  • How to create a Web Part in SharePoint To Show All List and List Items

    I did try this by reading the following article:
    http://www.dotnetcodesg.com/Article/UploadFile/2/217/Web%20Part%20in%20SharePoint%20To%20Show%20All%20List%20and%20List%20Items.aspx
    but when I am building that web part I am getting some errors
    public partial class ShowListUserControl
    : UserControl
    by default there is webpart written in place of UserControl and when I am changing this and build this program the error related to global WebPartTemplate comes in the function
    How can I solve this?
    Some one said to me that in Sandbox Webpart you can not create UserControl but the above article also is based on that.

    The article might have missed the step where the blogger might have missed the step. Read the following article and which confirms that you cannot use user controls in SB solutions.
    http://msdn.microsoft.com/en-us/library/gg615454.aspx
    If you are trying to build this in SharePoint 2013 then you must know that custom code is deprecated from SB solutions.
    Deprecation
    of Custom Code in Sandboxed Solutions
    For SP 2013 your best bet is to create an APP or create a farm solution (God please forgive me). :)
    Amit

  • How to force a new password in portal with LDAP user? external users

    With an external portal (used by agents that do not work for you or reside in your office), company policy is for password to be changed every qtr.
    If the users are creating as LDAP users how to force them to change their password when required?
    Is this a custom application that needs to be written so when they log into the portal if the qtr has expired the portal ask them to enter a new password that becomes valid for the next qtr.
    Versus internally deleting and emailing all the users a new password?

    Hi Glenn,
    We are getting one problem when we are creating user in LDAP and login with that user in  Portal that time we are getting Password change screen , but when we create a user in LDAP and change the password of that user in LDAP then when the user tries to  Login to portal that time we are not able to see the password change screen.
    But again if we change the password of that user through Portal we are able to see change password screen.
    can you help on this how we can force the user to change password when we are changing password in LDAP or in SAP System.
    Regards
    Trilochan

  • Custom web part in SharePoint Online for "User segments"

    Hi Experts,
    I was refferd here from the SharePoine Online community. http://community.office365.com/en-us/f/148/p/278071/851153.aspx 
    I was following this article to implement user segment in SharePoint Online http://blogs.msdn.com/b/adaptive_experiences_in_sharepoint_2013/archive/2012/11/14/set-up-user-segmentation-to-drive-adaptive-experiences-in-a-product-catalog-in-sharepoint-2013.aspx 
    However, this seems to require a custom web part to be build and deployed in SharePoint Online.
    Anyone has made user segment work in SharePoint Online? Anyone has done this custom web part before?
    Thank you,
    Aswath NS

    By default the Site Users web part shows all the users and groups who have been give direct permission to the site.  That would not include anyone who was given permission by being added to a group.  You can modify the web part settings to show
    a list of people in the Members group of the site or any other specific group.  But there is no setting to show all the users who have access.
    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

  • How to check if  web application already running?

    Is it any way to check, if a web application is already running on clients computer.  In other words how to prevent users to opens second instance of the same running application??

    Not sure what you mean.
    The application (scope) only runs once.  A user cannot force another application scope to open up, ColdFusion controls this.  If no request is made within the timespan set for the application timeout, then the next request fires off the onApplicationStar() BIF automatically before the request BIFs are executed.
    If you mean that you don't want them to have more than 1 browser open to the same website, I'm not sure that's going to cause any issues; as what was said before, the web is stateless.  ie:
    If I open Chrome, and in Tab 1 I goto home.cfm and in Tab 2 I goto home.cfm the to ColdFusion, it basically sees 2 requests to home.cfm made from (in essence) the same person (even though it doesn't know that until you implement some form of user tracking).
    But even if a person logs into a website, the session data is shared for the browser or session (depending in how your sessions are setup)  So even if he logs in on Tab 1, the next time he goes anywhere in Tab 2, it'll be when he's logged in.  The 2 tabs share the same session data.

  • How To Customize A web browser when running an application

    Hi,
    I have a little problem.
    I want to customize my web browser when i will deploy the application.
    fore example The browser Firefox have the following tabs: (File--Edition--History--BookMarks etc...)
    How can I proceed to avoid displaying these tabs in the page of the deployment of my application.
    Thanks Jdeveloper lovers

    Hi,
    Thank you shay it was a great step for the solution ,
    I can avoid watching Unwanted tabs.
    I hope frank you are not ungry against me ;)
    I am obliged it is a professional Requirement.
    Thank you for all Jdeveloper Lovers

  • How to force SequenceFi​leUnload callback to run from within operator interface

    I need to force SequenceFileUnload callback to run from within operator interface arbitrary, with possibility to control execution flow.
    I.e. discarding object handle of execution object, which has client sequence file, which has SequenceFileUnload callback, causes it(SequenceFileUnload callback) to run. Unfortunately, after discarding execution object handle, it can be used to control execution flow(pausing, aborting, terminating).

    Thanks for the clarification. Here are the answers to your 3 questions:
    1) You can programmatically run any sequence (including callbacks) by using the TestStand API Engine.NewExecution() method.
    2) The Execution API object has several control methods for breaking, aborting, terminating, restarting, etc... All you need to do is obtain a reference to the Execution you want to perform one of these actions on and call the appropriate method on the reference. If you start the SequenceFileUnload callback with the Engine.NewExecution method, this returns a reference to the Execution object that you can call these methods on. If you don't use the NewExecution method, you can do a check in your UIMsg event handler for the StartExecution UIMsg event
    for an execution starting that is running the SequenceFileUnload callback, and simply manipulate the Execution reference the UIMsg contains as you see fit.
    3) To disable the SequenceFileUnload callback for a sequence file that is currently loaded. You can set the SequenceFile API object property "UnloadCallbackEnabled" to FALSE, and the callback will not execute for that file when it is unloaded unless you go back and reset the property to true before unloading. Note this property is reset each time you load the file.
    For more information on the TestStand API objects, methods, and properties discussed in this post, refer to the TestStand Programmer Help accessed through the Sequence Editor's Help >> TestStand Programmer Help menu selection.
    Jason F.
    Applications Engineer
    National Instruments
    www.ni.com/ask

  • How to schedule a WebI Report for the list of users that it contains in it

    I have a WebI Report in BOXIr2 which contains the list of Employees Details (Employee Name, Mail ID, Emp Code) who had missed their timesheet for the week, Please let me know Is their a way that i can send mail notification through BO report Scheduling to the list of Employees who are listed in the Report, Thanks in advance !

    Hi,
    in BO XI 3.1 you can do this using a publication object. Unfortunately in XI R2 this works only for DeskI documents. You may want to consider using the BOE SDK for this. I must admit that I do not have a specific solution for you a workflow may look like this:
    1) Schedule your WebI with the user list to be exported on a network drive
    2) Build a java program that reads in the file, connects to the BOBJ repository and schedules the report using the recepient list.
    Regards,
    Stratos

  • How to make netcfg2 run with regular user permissions

    when i want to run netcfg2 to connect to my wireless i always have to be superuser then run netfg2.  is there anyway to let the regular user run netcfg2?

    sudo is your friend. You can also set it to only work with certain commands. Instead of having
    USER_NAME   ALL=(ALL) ALL
    You can have
    USER_NAME   ALL=/usr/bin/netcfg2./usr/bin/netcfg-menu,[any other commands you want to add]

  • How to force password policy requirements on password resets for user accounts reset by the Administrator?

    OS: Windows Server 2008 R2 Enterprise
    Domain Level: 2008
    Forest Level: 2000
    We have Domain Administrators in our domain that reset passwords for user accounts, and the passwords the Administrators set them to are not being enforced follow our default domain password policy. For example, I log on the domain controller, as an administrator
    and can reset a password for a user account to be blank. 
    Is there a reason Domain Administrator password resets for user accounts are not enforced by our default domain password policy? Is there a way to enforce this on password resets by Domain Admins? 

    Do you have fine grant password policy? If not ; by default all the usrs are effected by domain level password policy even domain admins,
    Regards~Biswajit
    Disclaimer: This posting is provided & with no warranties or guarantees and confers no rights.
    MCP 2003,MCSA 2003, MCSA:M 2003, CCNA, MCTS, Enterprise Admin
    MY BLOG
    Domain Controllers inventory-Quest Powershell
    Generate Report for Bulk Servers-LastBootUpTime,SerialNumber,InstallDate
    Generate a Report for installed Hotfix for Bulk Servers

  • How can I resize the size of the Excel web part?

    I have a spreadsheet that i want to use to populate a page in my SharePoint site.  i copied the workbook to the site, created the page and added the excel web part. then i linked the workbook to the web part and submitted.  it displays but only
    about 25% of the sheet shows. i dont want to use the thumbs to scroll inside the web part. i want the web part sized to show the entire spreadsheet.  cant seem to find how to size the web part. Can some kind soul help me out here.
    thanks

    Hi,
    According to your post, my understanding is that you wanted to resize the size of the Excel web part.
    Per my knowleadge, most of the time excel web parts turn out ugly, due to the fact that they’re rendered in an iframe and therefore the browser doesn’t resize the container to fit the content.
    As a workaround, we can edit the page where you want the resizing to happen, add in a content editor web part, and paste the following code into the source editor.
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function () { // resizes excel webparts
    $("td[id^='MSOZoneCell_WebPart']").each (function (i, e) {
    var findIframe = $(e).find ("iframe:first");
    if (findIframe &amp;&amp; findIframe.attr ("scriptforiframecontent"))
    bindEwaLoaded ("#"+e.id);
    function bindEwaLoaded(obj) { // bind event to the web part
    $(obj).bind ("ewaLoaded", function (e) {
    var b = $(e.target).find ("iframe:first").attr ("postedbackalready");
    if (b == undefined) // loop until iframe is ready
    setTimeout (function() { $(e.target).trigger ("ewaLoaded"); }, 1000);
    else // try to resize now
    ewaSetSize (e.target);
    }).trigger ("ewaLoaded"); // first trigger now
    function ewaSetSize(obj) { // resize elements
    // configure paddings
    var excelObjectWidthPadding = 50;
    var excelObjectHeightPadding = 50.
    var w, h, div1, div2;
    var e = $(obj).find ("iframe:first").contents().find ("table.ewrnav-invisibletable-nopadding:last");
    if (e.length != 0) { // excel table
    w = e.width ();
    h = e.height ();
    div1 = $(obj).find ("table:first> tbody:first> tr:eq(1)> td> div> div");
    div2 = $(div1).find ("table:first> tbody:first> tr:eq(1)> td> div");
    } else {
    e = $(obj).find ("iframe:first").contents().find ("div.ewrchart-img-div");
    if (e.length != 0) { // excel chart
    w = e.width ();
    h = e.height ();
    div1 = $(obj).find ("table:first> tbody:first> tr:eq(0)> td> div> div");
    div2 = $(div1).find ("table:first> tbody:first> tr:eq(1)> td> div");
    if (w == 0 || w == undefined) { // loop until content is ready
    setTimeout (function() { ewaSetSize (obj); }, 1000);
    } else { // do resize
    w += excelObjectWidthPadding;
    h += excelObjectHeightPadding;
    div1.width (w);
    div2.height (h);
    </script>
    For more information:
    Automatically resizing Sharepoint Excel Web Parts
    JQuery for Everyone: Dynamically Sizing Excel Web Parts
    Dynamically re-sizing excel services webparts
    Thanks,
    Jason
    Jason Guo
    TechNet Community Support

  • How to create web part and retrieve data from a scheduled task?

    Hi,
    I am new to SP, so I think you can guide me. I have  a scheduled task which gets currency data. I wonder if there is  way to show them on a web part. There will be currnecy names, buy and sell data on this web part. I would be glad if you can show
    me step by step how to create this web part on SP.
    Thanks in advance.
    Best Regards.

    Hi,
    thanks for the reply so I advice on that case to write code in the task schedule to write the data into a SharePoint list, if the scheduled task is on the same server as SharePoint then use Object model if it on another server then use client object model
    to write data to a list
    then on SharePoint site you will just add out of the box web part to display the list where you stored the data
    to save data using Object model:
    http://msdn.microsoft.com/en-us/library/office/ms467435(v=office.14).aspx
    http://www.go4sharepoint.com/Code/insert-list-item-sharepoint-object-286.aspx
    to save data using client object model
    http://www.codeproject.com/Articles/268196/SharePoint-Client-Object-Model
    Kind Regards,
    John Naguib
    Technical Consultant/Architect
    MCITP, MCPD, MCTS, MCT, TOGAF 9 Foundation
    Please remember to mark your question as answered if this solves your problem

Maybe you are looking for

  • Remote access VPN on PIX525 issues.

    Hi I was wondering if anybody had any ideas about my remote access VPN. Its configured on a Cisco PIX525 running ver 6.3(5) (old I know!) and I am running Cisco VPN client ver 5.06.0160 on the client end. Ok so here's the thing. The client connects o

  • Swr30 and Galaxy Note 4

    Hi. I'd appreciate your help on this. I can't get email and text message notifications to appear on my smart band talk with my Samsung Note 4. Have reset it and reinstalled the app multiple times. Thanks

  • Why don't I have the screen resolution I used to have on my iMac 2400.

    I used to have several screen resolutions on my iMac 2400, now I only have two, 1920 X 1200 and 960 X 600. Because I am a senior, my eyes need a resolution that provides clarity and is not too small.  960 X 600 prevents me from using Microsoft Office

  • Problem booting in OS X 10.3

    I have a G5 that was running Mac OS X 10.3. I had an issue with Roxio Toast and the system crashed. When I rebotted the machine it would come up and just sit on a folder with a question mark in it. i tried repairing the disc but it could not do it. I

  • Changing a tree's xml data

    I've been updating my trees xml data by doing this: var node:XML = stTree.selectedItem as XML; var p:* =node.parent(); var c:* =node.childIndex(); var s:* = stTree.selectedIndex; var insert:XML = new XML('<i item="some stuff">'); stTree.dataDescripto