Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie - how to hide toolbar/link for spesific group

Status
Not open for further replies.

Winan

IS-IT--Management
Jan 1, 2002
83
ID
Dear all,

I am very new to SPS, I have just installed SPS 2003 on my Win 2003 Server, I had 2 groups of user, group A is administrator users who can do anything to portal and the others is just normal user who can only view and cannot do anything to portal.

What I need is when normal users logged in to portal then every toolbar / links for modifying the portal should be invisible.. , currently although they cannot modify anything to portal but they can still see the toolbar/link, how to deal with this?

please advise .. many thanks in advance

Regards

Winanjaya
 
Hi, well this hiding links question is asked alot on sharepoint, because its not possible by default...

If you want this behavior you need to implement it you self..

The top links you can show as hyperlinks in a webpart where you do your own autorizing (example will follow). You just delete the standard links in Frontpage.. Then you still have your dropdowm menu for placing webparts and stuff. You can hide this by placing a <div id="hidediv" style="visibility: hidden"> </div> around it.
The webpart changes the style of this div when an admin is logged in.

now an example:

Code:
StringBuilder sbText = new StringBuilder();
SPSite SiteCollection;
SPWeb Web;
using(SiteCollection = new SPSite(<topSitePath>))
using(Web = SiteCollection.OpenWeb())
{			
SiteCollection.CatchAccessDeniedException = false;
                
sbText.Append("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");

if (Web.Permissions.DoesUserHavePermissions(SPRights.ManageWeb))
{	
    sbText.Append("<tr><td><hr></td></tr>");
    sbText.Append("<tr><td><a href='_layouts/1043/settings.aspx'>Site-Settings</a></td></tr>");
    sbText.Append("<tr><td><a href='_layouts/1043/create.aspx'>Create</a></td></tr>");
    sbText.Append("<tr><td><a href='_layouts/1043/viewlsts.aspx'>Documents and Lists</a></td></tr>");
sbText.Append("<tr><td><a href='javascript:HelpWindowKey(%22NavBarHelpHome%22)'>Help</a></td></tr>");
}
sbText.Append("</table>");
				
if (Web.Permissions.DoesUserHavePermissions(SPRights.ManageWeb))
{	
 sbText.Append("<script type='text/javascript'>");
 sbText.Append("document.getElementById('hidediv').style.visibility = 'visible';");
 sbText.Append("</script>");
                    }
                }

This webpart needs to be placed below the hide div tag!

I hope this helps...
 
I was missing 1 line:
Code:
output.Write(sbText.ToString());
 
But how if administrator group want to modify some item in portal.. is it possible? .. please advise

Regards
Winanjaya
 
yes it is because thats what this part does, it make the links and Menu available by checking if the user has SPRights.ManageWeb right.. and Admin.. and than printing those links to the screen and the javascript unhides the div arount the menu..

I hope is a little clearer now!
 
Thanks, almost clear now, sorry, I am very new with this, where can I put that codes? .. please advise

Thanks again

Regards
Winanjaya
 
do you have VB.NET version of that code? .. please advise

Thanks and Regards
Winanjaya
 
In VB.NET i just used a convertor on the Inet.

Code:
Dim sbText As StringBuilder = New StringBuilder 
Dim SiteCollection As SPSite 
Dim Web As SPWeb 
' Using 
SiteCollection = New SPSite("<topSitePath>") 
Try 
 ' Using 
 Web = SiteCollection.OpenWeb 
 Try 
   SiteCollection.CatchAccessDeniedException = False 
   sbText.Append("<table width='100%' border='0' cellspacing='0' cellpadding='0'>") 
   If Web.Permissions.DoesUserHavePermissions(SPRights.ManageWeb) Then 
     sbText.Append("<tr><td><hr></td></tr>") 
     sbText.Append("<tr><td><a href='_layouts/1043/settings.aspx'>Site-Settings</a></td></tr>") 
     sbText.Append("<tr><td><a href='_layouts/1043/create.aspx'>Create</a></td></tr>") 
     sbText.Append("<tr><td><a href='_layouts/1043/viewlsts.aspx'>Documents and Lists</a></td></tr>") 
     sbText.Append("<tr><td><a href='javascript:HelpWindowKey(%22NavBarHelpHome%22)'>Help</a></td></tr>") 
   End If 
   sbText.Append("</table>") 
   If Web.Permissions.DoesUserHavePermissions(SPRights.ManageWeb) Then 
     sbText.Append("<script type='text/javascript'>") 
     sbText.Append("document.getElementById('hidediv').style.visibility = 'visible';") 
     sbText.Append("</script>") 
   End If 

output.Write(sbText.ToString)
 
Hi..
I tried it .. but it returned with error below:

The dependency 'Microsoft.SharePoint.Dsp' could not be found.
The dependency 'Microsoft.SharePoint.Library' could not be found.
The dependency 'Microsoft.SharePoint.Security' could not be found.

I didnot find the above files on my SPS 2003, do you have any suggestion?

TIA
Winanjaya
 
Did you base the project on the Visual studio Webpart template? That would be the best thing to do because then everything needed is present.

I believe you use SPS, i use WSS, but you need a reference to Microsoft.Sharepoint this dll is located in "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\ISAPI\Microsoft.SharePoint.dll" (on WSS at least)

also use these Usings: (imports in VB.NET)
System
System.Text
System.Web.UI
System.Xml.Serialization
System.ComponentModel
Microsoft.SharePoint
Microsoft.SharePoint.WebPartPages
Microsoft.SharePoint.WebControls
 
After I added

Imports Microsoft.SharePoint.WebControls

it compiled with no error or warning..

and then how to implement it? .. please advise

TIA

Winanjaya
 
For implementing i advise you follow the steps that are decriped in a resource i mentioned earlier in the post (and URL).

basicly edit the web.config of the sharepoint server so that the line <trust level="WSS_Minimal" originUrl="" /> reads: <trust level="Full" originUrl="" />

add a safecontrol tag in the web.config:
<SafeControl Assembly="<assemblyname>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=<public token key>" Namespace="<namespace>" TypeName="*" Safe="True" />

you need to specify:
<assemblyname>
<public token key>
<namespace>

The public token key you can get by first adding a key pair to your project(you should have done this if you followed the steps in the article)
but just in case make a new keypair by running:
(run/cmd <enter>)
cd \Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\sn.exe -k c:\SharePoint.snk

now add this new keyfile to your project in the assembly info file:
[assembly: AssemblyKeyFile("c:\\SharePoint.snk")] - it looks a bit different in VB.NET

then do run/cmd <enter>
cd \Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\sn.exe -T "c:\webpartname.dll" - make sure the location is correct. This will return a key.. use this key in the Web.config as i mentioned earlier.

and also edit/make (comes standard with a webpart library project) the name.dwp
example:
Code:
<?xml version="1.0"?>
<WebPart xmlns="[URL unfurl="true"]http://schemas.microsoft.com/WebPart/v2">[/URL]
   <Assembly>[YOUR ASSEMBLY NAME], Version=1.0.0.0, Culture=Neutral, PublicKeyToken=[YOUR KEY]</Assembly>
   <TypeName>[YOUR NAMESPACE].[YOUR ASSEMBLY NAME]</TypeName>
   <Title>Title</Title>
   <Description>Description</Description>
</WebPart>


now goto your site and import the new webpart by opening the dwp file and drag it on the page.

i forgot to mention before you need to place the assembly(DLL) in the bin map of the website or load it to the GAC.

I hope this helps but i should realy follow the article step by step!

I hope this helps... it should atleast help anyone who always wondered how to create webparts :p
 
Hi,
I tried the step by step and almost finish, now I cannot drag my webpart into the page, I met the following message:

A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe.

I also added a safecontrol tag to my all of web.config

<SafeControl Assembly="LGIHideLinks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=59280c456239b7f0" Namespace="LGIHideLinks.HideLinks" TypeName="*" Safe="True" />

I need advise .. many thanks in advance

Regards
Winanjaya
 
Ok .. please ignore my previous message, it works now but with below error:

The "HideLinks" Web Part appears to be causing a problem.

is there any log file or something for determine what's that means?

regards
Winanjaya
 
No but you can put

try{

<code goes here>

}
catch (Exception ex){
output.Write(ex.Message + "<br>" + ex.Stacktrace);
}

around your code, this should give you hints about what is going wrong.
 
I just remembered you use VB.NET so here is the VB.Net example:

Try

<code goes here>

Catch ex As Exception
output.Write(ex.Message + "<br>" + ex.Stacktrace)
End Try
 
Hello,
I got no better progress, I did not get the hints
I need advise .. what should I do? .. many thanks in advance

Regards
Winanjaya


Protected Overrides Sub RenderWebPart(ByVal output As System.Web.UI.HtmlTextWriter)
Dim sbText As StringBuilder = New StringBuilder
Dim SiteCollection As SPSite
Dim Web As SPWeb
SiteCollection = New SPSite("<topSitePath>")
Try
Web = SiteCollection.OpenWeb
Try
SiteCollection.CatchAccessDeniedException = False
sbText.Append("<table width='100%' border='0' cellspacing='0' cellpadding='0'>")
If Web.Permissions.DoesUserHavePermissions(SPRights.ManageWeb) Then
sbText.Append("<tr><td><hr></td></tr>")
sbText.Append("<tr><td><a href='_layouts/1043/settings.aspx'>Site-Settings</a></td></tr>")
sbText.Append("<tr><td><a href='_layouts/1043/create.aspx'>Create</a></td></tr>")
sbText.Append("<tr><td><a href='_layouts/1043/viewlsts.aspx'>Documents and Lists</a></td></tr>")
sbText.Append("<tr><td><a href='javascript:HelpWindowKey(%22NavBarHelpHome%22)'>Help</a></td></tr>")
End If
sbText.Append("</table>")
If Web.Permissions.DoesUserHavePermissions(SPRights.ManageWeb) Then
sbText.Append("<script type='text/javascript'>")
sbText.Append("document.getElementById('hidediv').style.visibility = 'visible';")
sbText.Append("</script>")
End If
output.Write(sbText.ToString)
Catch ex1 As Exception
output.Write("Ex1: " & ex1.Message + "<br>" + ex1.StackTrace)
Finally
End Try
Catch ex2 As Exception
output.Write("Ex2: " & ex2.Message + "<br>" + ex2.StackTrace)
Finally
End Try
End Sub
 
Private SiteCollection As SPSite = SPControl.GetContextSite(Context)
Private Web As SPWeb = SPControl.GetContextWeb(Context)

Ok you where suppost to fill in the <topSitePath> tag ;)
but just do this:

Replace->SiteCollection = New SPSite("<topSitePath>")
With ->SiteCollection = SPControl.GetContextSite(Context)

and

Replace->Web = SiteCollection.OpenWeb
With ->Web = SPControl.GetContextWeb(Context)
-----------------------------------------------

If Web.Permissions.DoesUserHavePermissions(SPRights.ManageWeb) Then
sbText.Append("<script type='text/javascript'>")
sbText.Append("document.getElementById('hidediv').style.visibility = 'visible';")
sbText.Append("</script>")
End If

Also only use this piece of the code only when you have placed the webpart directly below the "Edit Shared Page menu" (just move the menu), and have placed a <div id="hidediv" style="visibility: hidden"> </div> around the menu in Frontpage 2003!

Ok goodluck once more! Let me know if it finally works, i might be overlooking some VB.Net thingy because i wrote it in C#!
 
BTW you didnt get any hint because the part that was wrong was above you try tag ;) (-> SiteCollection = New SPSite("<topSitePath>"))

The next time use atleast one try-catch tag that covers all the code in that section example: (and believe me Webparts are fun when you get the hang of it!)
Example:
Code:
Protected Overrides Sub RenderWebPart(ByVal output As System.Web.UI.HtmlTextWriter)
   Try

   [B]<ALL CODE GOES HERE!>[/B]

   Catch ex As Exception
      output.Write("Ex: " & ex.Message + "<br>" + ex.StackTrace)
   Finally //<-- !This one is optional! 
   End Try
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top