Showing posts with label Sharepoint. Show all posts
Showing posts with label Sharepoint. Show all posts

Wednesday, 15 May 2013

manage show hide site actions sharepoint sp2010

How to manage visibility ( show/hide ) of Site Actions by user in Sharepoint

 

If you want to show site actions menu by user rights easy way of to do that using SPSecurityTrimmedControl .
Conditionally renders the contents of the control to the current user only if the current user has permissions defined in the PermissionString
<SharePoint:SPSecurityTrimmedControl runat=”server” PermissionsString=”ManageWeb”>
<div class=”ms-siteaction”>
….
</div>
</SharePoint:SPSecurityTrimmedControl>
Parameters and attributes:
  • PermissionString:



EmptyMask Has no permissions on the Web site. Not available through the user interface.

ViewListItems View items in lists, documents in document libraries, and view Web discussion comments.

AddListItems Add items to lists, add documents to document libraries, and add Web discussion comments.

EditListItems Edit items in lists, edit documents in document libraries, edit Web discussion comments in documents, and customize Web Part Pages in document libraries.

DeleteListItems Delete items from a list, documents from a document library, and Web discussion comments in documents.

ApproveItems Approve a minor version of a list item or document.

OpenItems View the source of documents with server-side file handlers.

ViewVersions View past versions of a list item or document.

DeleteVersions Delete past versions of a list item or document.

CancelCheckout Discard or check in a document which is checked out to another user.

ManagePersonalViews Create, change, and delete personal views of lists.

ManageLists Create and delete lists, add or remove columns in a list, and add or remove public views of a list.

ViewFormPages View forms, views, and application pages, and enumerate lists.

Open Allow users to open a Web site, list, or folder to access items inside that container.

ViewPages View pages in a Web site.

AddAndCustomizePages Add, change, or delete HTML pages or Web Part Pages, and edit the Web site using a SharePoint Foundation–compatible editor.

ApplyThemeAndBorder Apply a theme or borders to the entire Web site.

ApplyStyleSheets Apply a style sheet (.css file) to the Web site.

ViewUsageData View reports on Web site usage.

CreateSSCSite Create a Web site using Self-Service Site Creation.

ManageSubwebs Create subsites such as team sites, Meeting Workspace sites, and Document Workspace sites.

CreateGroups Create a group of users that can be used anywhere within the site collection.

ManagePermissions Create and change permission levels on the Web site and assign permissions to users and groups.

BrowseDirectories Enumerate files and folders in a Web site using Microsoft Office SharePoint Designer 2007 and WebDAV interfaces.

BrowseUserInfo View information about users of the Web site.

AddDelPrivateWebParts Add or remove personal Web Parts on a Web Part Page.

UpdatePersonalWebParts Update Web Parts to display personalized information.

ManageWeb Grant the ability to perform all administration tasks for the Web site as well as manage content. Activate, deactivate, or edit properties of Web site scoped Features through the object model or through the user interface (UI). When granted on the root Web site of a site collection, activate, deactivate, or edit properties of site collection scoped Features through the object model. To browse to the Site Collection Features page and activate or deactivate site collection scoped Features through the UI, you must be a site collection administrator.

UseClientIntegration Use features that launch client applications; otherwise, users must work on documents locally and upload changes.

UseRemoteAPIs Use SOAP, WebDAV, or Microsoft Office SharePoint Designer 2007 interfaces to access the Web site.

ManageAlerts Manage alerts for all users of the Web site.

CreateAlerts Create e-mail alerts.

EditMyUserInfo Allows a user to change his or her user information, such as adding a picture.

EnumeratePermissions Enumerate permissions on the Web site, list, folder, document, or list item.

FullMask Has all permissions on the Web site. Not available through the user interface.
  • PermissionContext:



CurrentSite Apply a permission mask to the current site.

CurrentList Apply a permission mask to the current list.

CurrentItem Apply a permission mask to the current list or document library item.

RootSite Apply a permission mask to the root site of the site collection.

CurrentFolder Apply a permission mask to the current folder.
  • PermissionMode

All The user must have all of the rights specified in the permission mask to view a link.

Any The user must have only one of the rights specified in the permission mask to view a link.
Happy Codding…

 

Redirect Old MOSS 2007 to sp2010



How to redirect Old MOSS 2007 ( IIS6.0 ) Site to New SharePoint 2010 Site in Migration:

Requirement is, 
We have migrated contents from MOSS 2007 (IIS6.0) to SharePoint 2010 and gradually moved site collections one by one It took a while to address migration fixes and make them in a good shape for some  site collection.



Meanwhile, We had to redirect Users to migrated SharePoint 2010 site collections when they hit old MOSS 2007 site collection URLs or access them from bookmarks. Ideally, once migration is completed, we must place a server redirect in publishing server to send users from old URL to new URL.



But in our case, As we move site collections one by one, only few site collections needs to be redirected.



Redirection URL scope would be varied  from site level or site collection level or list & document library level.

The solution, we need to below options,

  1. Create custom httpmodule to redirect httprequest and make entries to web.config.
  2. Third Party tool  ( ISAPI rewrite URL ) available at free of cost from codeplex. URL mapping using regex ( regular expression validator rule )  available. for more details, refer http://rdacollaboration.codeplex.com/
  3. If Source site is IIS7.0, refer this at free of cost http://www.iis.net/downloads/microsoft/url-rewrite


Wednesday, 22 August 2012

class library dll’s not added / installed / referenced / moved to assembly GAC while deployment of package automatically in SharePoint SP 2010 / 2007

To install classlibrary dll to GAC automatically during the deployment of WSP package of Sharepoint SP 2007 / 2010, refer the following instruction steps,

1. Open the Package designer in the SharePoint project.
2. Select the Advanced tab.
3. Click the Add button.
4. Select the Add Assembly from Project Output menu item.
5. Use the Source Project dropdown to select which project in your solution should have its assembly included.
6. Make sure the Deployment Target is set to GlobalAssemblyCache.
7. Click OK.
8. Repackage and redeploy the SharePoint project. 

The WSP package should now contain the class library's assembly and the WSP's package manifest should have been updated according.,

For more details, please refer : 

Tuesday, 14 August 2012

How to delete Corrupted / errored list / picture library in SharePoint SP 2010 /2007

The reason for  error like " Exception from HRESULT 0×81070215  " is custom list definition and list instance is not properly defined. That means field / columns in the content type has issues with that (some necessary fields / column might not be be defined there)
Please try to fix this by doing correct list definition, list instance and its content type otherwise delete the list using stsadm.exe force delete command

If you receive error Exception from HRESULT 0×81070215 when you open a list in browser or access the SharePoint site manager, a list has not properly been deleted and is in a corrupted state, which means you can not able to delete using browser hence you have to delete the corrupted list using stsadm forcedeletelist command.

Steps:

  • Go to start->run->cmd (it will open command window)
  • For Sharepoint 2007, Use cd C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN. 
  •  For Sharepoint 2010, Use cd C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN.
  • To find the help for forcedeletelist user following command,
    • Stsadm –help forcedeletelist
  • To delete particular corrupt list use following command,

Thursday, 26 July 2012

Hiding / showing the SharePoint SP 2010 Ribbon From Anonymous restricted limited access Users in master edit page Privilege


How to hiding or showing ribbon control (with navigation breadcrumb) for anonymous or read access users like visitor or limited access users in sharepoint 2010 ( SP 2010 ) dynamically based on user's access:


SharePoint 2010 introduced new feature called “ Ribbon “ and it provides great user experience for users with elevated privileges, like contributors and site owners. However, Its not suggested for users with lease privilege, such as visitors and anonymous users since most of features are applicable for them.
SPSecurityTrimmedControl which  is used to show / hide the ribbon control.

Steps:

1)      Open your SharePoint master page to edit it.

2)      Find the following line wth the highlighted text in your master page.

       <div id="s4-ribbonrow" class="s4-pr s4-ribbonrowhidetitle">
     Note: This div only contains the whole part of out of box sharepoint ribbon control.

3)  To hide the above div element, Find the following line in your master page.

      <div id="s4-workspace"

4)  Now add the following code in your master page just above the “s4-workspace” div element.

   <Sharepoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControl2" runat="server" PermissionsString="ManagePermission">
    <script type="text/javascript">
        document.getElementById("s4-ribbonrow").style.display = "none";
    </script>
</
Sharepoint:SPSecurityTrimmedControl>

5)      To apply changes, Save the master page and publish it.




Assigning permission programmatically for document libray or list item sharepoint 2010 code sp 2010


How to access or Assigning permission dynamically to Document library / List library / List Item / picture library on folder in sharepoint 2007 / 2010 ( SP 2010 ) code :

Windows SharePoint 2010 / 2007 provides Services manages permissions through Roles and Responsibilities. SPRoleDefinition and SPRoleDefinition classes provides methods to assign users to roles such as “Contributor” or “Site Owner” or “Reader.

Sample solution code:

Following code demonstrate how to assigning / access “Reader” to custom SharePoint group “customgroup” programmatically on Folder of a document library for a custom sharepoint group by code method

using (SPSite site = new SPSite(siteCollection))
{
  using (SPWeb web = site.OpenWeb(siteName))
  {
    SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists[libraryName];
    //Get folder
    SPListItem item = docLib.Folders[1];
    if (!item.HasUniqueRoleAssignments)
      item.BreakRoleInheritance(true);
    SPRoleAssignment roleAssignment = new SPRoleAssignment(“customgroup”);
    SPRoleDefinition roleDefination = web.RoleDefinitions["Reader "];

    roleAssignment.RoleDefinitionBindings.Add(roleDefination);
    item.RoleAssignments.Add(roleAssignment);
    item.Update();
  }
}

Assigning permission programmatically for site collectin and its sub site item sharepoint 2010 code sp 2010

How to Assigning permission programmatically / dynamically to site collection or its sub site in sharepoint 2007 / 2010 ( SP 2010 ) code

Windows SharePoint 2010 / 2007 (SP 2010) Service manages permissions through Roles and Responsibilities. SPRoleDefinition and SPRoleDefinition classes provides methods to assign users to roles such as “Contributor” or “Site Owner” or “Reader”

Sample solution code:

Following code demonstrate how to assign / access  “Reader” to custom SharePoint group “customgroup” programmatically / dynamically by code class method and access the site collection and its sub sites as “reader” permission in sp2010.


using (SPSite site = new SPSite(siteCollection))
{
  using (SPWeb subWeb = site.OpenWeb(siteName))
  {
    //You need to break role inheritence if you want to assign unique permission to subsite
    if (!subWeb.HasUniqueRoleAssignments)
      subWeb.BreakRoleInheritance(true);
    SPRoleDefinition roleDefination = parentWeb.RoleDefinitions["Reader"];
    SPRoleAssignment roleAssignment = new SPRoleAssignment("customgroup");
    roleAssignment.RoleDefinitionBindings.Add(roleDefination);
    subWeb.RoleAssignments.Add(roleAssignment);
    subWeb.Update();
  }
}

Wednesday, 25 July 2012

Delete Close Web Parts SharePoint 2010 url


How to delete or close Web Parts on SharePoint 2010 or What is The URL for deleting or closing webparts in sharepoint 2007 / 2010 pages :

Using webpart Maintenance Page mode:


We just need to  go to the Web Part Maintenance Page of SharePoint 2010. and then append just , ?contents=1

This URL of Maintenance Page of SharePoint 2010, will display all webparts which were used in page.
This URL will show all current using webparts and closed webparts ( not deleted webparts).

Sample solution URL for delete or close the webpart would be like,

http://yourdomain.com/pages/home.aspx?contents=1


Using Normal Manual Mode :
 
To delete a Web part, do the following:
1. Open the page where the Web part is located.
2. Select Edit Page from the Site Actions drop-down menu.
3. Click the Web part to be deleted.
4. Click the Web Part Tools tab on the Ribbon.
5. Click the Delete Button, and then click OK in the warning dialog.
 

Sunday, 8 April 2012

Steps to create and reorder a tab in FAST search center SP 2010

How to create and reorder a tab in FAST search center Sharepoint 2010

Steps:

1.Open the SharePoint site.
2.Go to ->Site Actions->View all Contents
3.We have two lists namely – “Tabs in Search Pages” and “Tabs in Search Results” which controls the tab in Search page and Search results page respectivly.



4.Open the list “Tabs in Search Pages”.
5.Click on Item in the ribbon control present at the top of the page and select “New Item”.
6.A form appears. Provide the proper tab name. (eg:“Old Site”).
7.In the Page filed we need to enter the page name, this can be out-of-the box page name or create a new page and include it.
Follow the above steps for the other list also.





Steps to reorder the tabs displayed in the Search center

There is No UI for changing the order of the Tab that appears in Search Center. There is two work around available for this, But the below one would be the easiest one.
1.Open the SharePoint site.
2.Go to “Site Actions”->”View All Site Contents”
3.Select the list ”Tab in search page”
4.Click on “List” in the ribbon control present at the top of the page.
5.Select ”List Settings” present at the right hand corner of the tab that appears when clicked on “List”
6.In the URL change the “listedit.aspx” to “reorder.aspx”








7.Change the order and save it.
8.Still we have to make one more thing before we see the correct order in search center.
9.Go back to the list “Tabs in Search Pages” and edit any of the items (no changes required) just save it again to let SharePoint know that some modification is happen in the TAB.

Remove / delete list item using client object model (ecma script) in sp 2010

How to delete / remove list item using client object model (ecma script) in sharepoint 2010?
ECMAscript is a kind of javascript or jquery.

Sample code demo:


function deleteProduct(productId) {
var itemid= "1";
    var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getByTitle('listname');
    var itemToDelete = list.getItemById(itemid);
    itemToDelete.deleteObject();
    context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
}

function success() {
    alert('success');
}
function failed(sender, args) {
    alert('failed. Message:' + args.get_message());
}

add new list item using client object model in sp 2010

How to add / create new list item using client object model (ecma script) in sharepoint 2010?

ECMAscript is a kind of javascript or jquery.

Sample code demo:

function addProduct() {
    try {
var itemname= "Mame 1";
var itemdesc="item desc1;";
        var context = new SP.ClientContext.get_current();       
        var web = context.get_web();
        var list = web.get_lists().getByTitle('listname');

        var listItemCreationInfo = new SP.ListItemCreationInformation();
        var newItem = list.addItem(listItemCreationInfo);
        newItem.set_item('ItemName', itemname);
        newItem.set_item('ItemDesc', itemdesc);
     
        newItem.update();
        context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
    }
    catch (e) {
        alert('error:' + e.Message);
    }
}

function success() {
    alert('success');
}
function failed(sender, args) {
    alert('failed. Message:' + args.get_message());
}

Friday, 6 April 2012

Get List and set list Items using Ecma script Client Object model using SharePoint 2010

How to Get List item and set list Items using Ecma script ( Client Object model) using SharePoint SP 2010 :

For my scenario, I have  to update the news count of news list ("NewsListName") based on the user viewed click count.
So, i have to get the current value of custom list item and update the same with the increment value of 1.

The following code will demonstrate how to get and update list item from client side script itself by using ecma script (client object model) in Sp 2010.

ecma script is a kind of java script which is used to update items without using any page postback / server side code in sharepoint 2010.

Sample code example:

source:

<a href="#" onclick="updatenewscount(newsid);">news title</a>

script:
 
<SharePoint:ScriptLink Name="SP.js" runat="server" LoadAfterUI="true" Localizable="false" />
-OR-
<script language="ecmascript" type="text/ecmascript" src="SP.js" />

<script language="ecmascript" type="text/ecmascript">
var newslist;
var web;
var context;
var newsid;
var newsitem;
var newscount = "Count";


function updatenewscount(itemId)
{
    newsid = itemId;

    context = new SP.ClientContext.get_current();
    web = context.get_web();
    newslist = web.get_lists().getByTitle("NewsListName");
    newsitem = newslist.getItemById(newsid);

    context.load(newslist);
    context.load(newsitem);
    context.executeQueryAsync(OnNewslistsLoaded);
}

function OnNewslistsLoaded()
{
    var currentcount = newsitem.get_item(newscount);

    newsitem.set_item(newscount, parseInt(currentcount)+1);
    newsitem.update();

    // Submit the query to the server
    context.load(newsitem);
    context.executeQueryAsync(OnNewsUpdated, OnError);   
}

function OnNewsUpdated (args)
{
     Alert(‘news count updated’);
}

function OnError(sender, args)
{
    alert(args.get_message());
}
</script>

Monday, 26 March 2012

Caml query compare between date range from today in sharepoint 2010 (SP 2010) and

How to calculate date from the list items using caml  query and compare date range between from today in sharepoint 2010 (SP 2010):

For my scenario, My start should lbe less than today and expiry date should be greater than today date and list items should be displayed based on priority order column( ascending or descending order.). The date format should not be empty or null.

This caml query also check for boolean status whether it is active or not. (true or false)

We can use caml query builder to check this whether it is working or not.


Caml Query:

Using the SP2010 Client Object Model to update a list item

    <Where> 
      <And> 
        <And> 
           
            <Leq> 
              <FieldRef Name='StartDate' /> 
              <Value Type='DateTime' IncludeTimeValue='False'> 
                <Today /> 
              </Value> 
            </Leq> 
            <IsNotNull> 
              <FieldRef Name='StartDate' /> 
            </IsNotNull> 
          
           
            <Gt> 
              <FieldRef Name='EndDate' /> 
              <Value Type='DateTime' IncludeTimeValue='False'> 
                <Today /> 
              </Value> 
            </Gt> 
            <IsNotNull> 
              <FieldRef Name='EndDate' /> 
            </IsNotNull> 
          
        </And> 
        <Eq> 
          <FieldRef Name='Active' /> 
          <Value Type='Boolean'>1</Value> 
        </Eq> 
      </And> 
    </Where> 
    <OrderBy> 
      <FieldRef Name='EndDate' Ascending='True' /> 
    </OrderBy> 


Sys.InvalidOperationException occurs on Lists sharepoint 2010

Sys.InvalidOperationException occurs Error Type: SP.Permissionkind has already been registered in Sharepoint (SP 2010):


Error : Type SP.PermissionKind has already been registered.


The only reason for this error is that some script files included several times in page body.


This error occured while using the javascript client object model ( ecma script ) in applciation page. The solution for this error is that any references of the js files made twice would cause an exception like this.




Problem is in detail,

Had refrence to SP.js file and also using the ExecuteOrDelayUntilScriptLoaded(something, "sp.js"); in my applictaion page.

This caused the "not very explanatory" error.

What to do ?
 
So by removing this scriptlink would help to fix this error.

Saturday, 24 March 2012

add custom list from event receiver of feature activation using sp sharepoint 2010

How to add custom list from event receiver of feature activation dynamically and how to add spfieldtype.Text, spfieldtype.number, spfieldtype.number dropdown select  range limit in sharepoint sp 
2010:

The below sample code demonstrate how to add choice / dropdown value property for a particular column using event receiver of feature avtivation in sharepoint 2010.

This sample

ADD SPFieldType.Choice, SPFieldChoice with SPChoiceFormatType.RadioButtons

Code:

using Microsoft.SharePoint;
using System.Collections.Specialized;


public void OnActivated(SPFeatureReceiverProperties properties)

{
    SPWeb web = (SPWeb)properties.Feature.Parent;
   
    string url = new Uri(web.Url).AbsolutePath;
    SPDocumentLibrary docLib = (SPDocumentLibrary)web.GetListFromUrl("Shared Documents/Forms/AllItems.aspx");
  
    StringCollection categories = new StringCollection();
    categories.AddRange(new string [] {"Choice A", "Choice B", "Choice C"} );
    docLib.Fields.Add("MyNewField", SPFieldType.Choice, true, false, categories);
 
    SPFieldChoice fieldChoice = (SPFieldChoice)docLib.Fields["MyNewField"];
    fieldChoice.DefaultValue = "Choice A";
    fieldChoice.EditFormat = SPChoiceFormatType.RadioButtons;
    fieldChoice.Update();
    docLib.Update();
 

 

OR


SPListCollection lists = web.Lists;
SPList listitem = web.Lists.TryGetList("Listname");
if(listitem == null)
{
 lists.Add("Listname","Your comments here", SPListTemplateType.GenericList);
 SPList newitem = web.Lists["Listname"];
 newitem.Fields.Add("Name",SPFieldType.Text, true);  // for adding text,  true- indicateds this column is mandatory
 newitem.Fields.Add("Link",SPFieldType.URL, true);  // for adding URL,  true- indicateds this column is mandatory
newitem.Fields.Add("ItemCount",SPFieldType.Number, true);  // for adding number,  true- indicateds this column is mandatory

StringCollection categories = new StringCollection();  // for adding choice dropdown, true- indicateds this column is mandatory
    categories.AddRange(new string [] {"Choice A", "Choice B", "Choice C"} );
     newitem.Fields.Add("Range", SPFieldType.Choice, true, false, categories);
  newitem.OnQuickLaunch = true;
newitem.update();

// to display item on default load

SPView itemview = newFeatureList.DefaultView;
itemview.ViewFields.Add("Name");
itemview.ViewFields.Add("Link");
itemview.ViewFields.Add("ItemCount");
itemview.ViewFields.Add("Range");
itemview.update();
   
}

}