Blog Archive

Wednesday, August 24, 2011

Hide the "View All Site Content" Link in SharePoint

To hide the link of "View All Site Content" in SharePoint, open the Master Page in SharePoint Designer and find the SPSecurityTrimmedControl element. This element contains a Div with class ms-quicklaunchheader.

The PermissionString attribute of SPSecurityTrimmedControl element determines which users can view this content. So by changing the value of this attribute to "ManageWeb", only Administrators can see this link. But by changing this value the master page becomes unghosted but this is the simplest trick to hide the link from all other users.

See this page for a list of all the possible permission string values.  

Monday, November 29, 2010

Enable Session State in SharePoint 2007

Here's a procedure to enable Session State within your MOSS 2007 farm.

Our session state will be stored in our SQL Server database. 

This is required over the traditional memory-based session because of multiple application servers in a web farm architecture.

Secondly, in order for our web applications to store session variables in SQL, we need to "prep" the database for session state data. 


 

1.  Create a Shared Services Provider.  This is required in order to enable Session State and its content database is the location of our session data.  If you already have an SSP, you can use the existing one.

2.  If needed, associate your web application with this SSP (done by default if it is your first SSP).

3.  In Central Administration, under Application Management, choose Session State, and ensure that it is enabled.

4.  From a command prompt, navigate to the Microsoft.NET 2.0 Framework directory

(Typically:  C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727)

5.  Modify your web.config:

Uncomment the following line: 

<add name="Session" type="System.Web.SessionState.SessionStateModule" />

Modify the following line:

<pages enableSessionState="true" … />

6.  Run the following command:

aspnet_regsql.exe -S <server_name> -d <database_name> -ssadd -sstype c -E

 
 

Where:

<server_name>  is the database server where your database is located

<database_name>  is the content database of your shared services provider


 

Run aspnet_regsql.exe /?  for more information on the remaining options

How to Find out the Installation is MOSS 2007 or WSS 3.0

Here is the code which identifies the Installation is MOSS 2007 or WSS 3.0

/// <summary> 
/// Method to find out if a SharePoint installation is MOSS or WSS 3.0 
/// </summary> 
public static bool IsMOSS() 
{ 

   SPFeatureDefinitionCollection features =  SPContext.Current.Site.WebApplication.Farm.FeatureDefinitions; 
    if (features["OssNavigation"] != null && features["Publishing"] != null) 
        return true; 
    else 
        return false; 
}

Tuesday, November 23, 2010

Adding a SPUser to SharePoint Group

For adding a SharePoint user to a particular SharePoint group
following code can be useful.



SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite site = new SPSite(siteURL))
    {
      using (SPWeb web = site.OpenWeb())
      {
        Microsoft.SharePoint.Administration.SPWebApplication webApp = 
        web.Site.WebApplication;
        webApp.FormDigestSettings.Enabled = false;

        web.AllowUnsafeUpdates = true;
       //Assign role and add user to site
       SPGroupCollection groupColl = web.SiteGroups;
       if (GroupExists(groupColl, GroupName))
       {
         //Add the user to a group.
         SPGroup roleGroup = web.SiteGroups[GroupName];
         using (SPSite newSite = new SPSite(baseSiteURL))
         {
           using (SPWeb newWeb = newSite.OpenWeb())
           {
               reply = addUserToGroup(newWeb, roleGroup,
               userName, firstName, lastName, userEmailId);
            }
         }
       }
       else
       {
         reply = false;
       }
       web.Update();
       webApp.FormDigestSettings.Enabled = true;
    }
  }
 });

Another private method we have to write here.

private bool addUserToGroup(SPWeb web, SPGroup group, 
string userName, string FirstName, string LastName, string userEmail)
{
  bool updateFlag = false;
  try
  {
    //Make Allow unsafe updates true so that security problem should not come.
    web.AllowUnsafeUpdates = true;
    group.AddUser(userName, userEmail, FirstName, "Automatically Added User");
    group.Update();
    web.Update();
    updateFlag = true;
  }
  catch (Exception ex)
  {
     updateFlag = false; 
     throw ex;
  }
}

Sunday, August 1, 2010

Getting the Public Key Token of a DLL using "sn" Command

Getting the Public Key Token of a DLL using "sn" Command


For getting a Public Key Token first we have Sign the project.

1. Right click on the Project Properties and Select the Signing Tab.
2. Select the "New" From Dropdown List and Give Name of the file.
3. If we want more security then click give the Password else click OK.
4. Now we can see the .snk file in the project.
5. Build the Project.
6. Open the Visual Studio Tools and select the Command Prompt.
7. Now give the following command to get the public key token.

Sn -T Path of the DLL file including DLL Name with extension

8. This command will show the Public Key Token of the DLL file.
9. For storing the Public Key token of a DLL use the following Command.

Sn -T Path of the DLL file including DLL Name with extension

10. Now open the notepad and Paste and you can see the Public Key Token of the DLL File.