Wednesday, 4 April 2012

How to copy users between sharepoint groups in Sharepoint using C#

Hi,
One of the pain areas in sharepoint is to copy the users between the groups. The sharepoint does not support nesting of groups. The problem get worsen when you have huge number of users. To resolve this I have written this tool. This works in both versions of sharepoint MOSS 2007 and SPS 2010. This tool takes three input vales
1. Site Url
2. Name of the source sharepoint group (Case Sensitive).
3. Name of the destination sharepoint group (Case Sensitive).

The code for this tool is as below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace CopyUsersBetweenGroupsInSharepointByRR
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("This tool will copy the users from one group to another group");
            Console.WriteLine("Please enter the URL of the site where your groups are available");
            String siteUrl = Console.ReadLine();
            using (SPSite site = new SPSite(siteUrl))
            {
                try
                {
                    SPWeb web = site.OpenWeb();
                    Console.WriteLine("Please enter the name of the source group");
                    String sourceGroupName = Console.ReadLine();
                    Console.WriteLine("Please enter the name of the destination group");
                    String destinationGroupName = Console.ReadLine();
                    SPGroup sourceGroup = web.Groups[sourceGroupName];
                    SPGroup destinationGroup = web.Groups[destinationGroupName];
                    SPUserCollection sourceUsers = sourceGroup.Users;
                    SPUserInfo[] sourceUserInfoArray = new SPUserInfo[sourceUsers.Count];
                    for (int i = 0; i < sourceUsers.Count; i++)
                    {
                        sourceUserInfoArray[i] = new SPUserInfo();
                        sourceUserInfoArray[i].LoginName = sourceUsers[i].LoginName;
                        sourceUserInfoArray[i].Name = sourceUsers[i].Name;
                    }
                    destinationGroup.Users.AddCollection(sourceUserInfoArray);
                    destinationGroup.Update();
                    web.Update();
                    Console.WriteLine("Operation Completed Successfully");
                    Console.ReadLine();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.ReadLine();
                }
            }
        }
    }
}

I hope this will help you out.

Thanks,
Rahul Rashu

Sunday, 25 March 2012

How to edit a list item by clicking on its title in Sharepoint 2010


Hi,

I received a request from someone to modify a list view in such a manner that if some click on the title of the item it should take him to the edit page instead of display page in sharepoint 2010. I have already managed to do this in sharepoint 2007 and have written an article on it here http://rahulrashu.blogspot.in/2012/03/how-to-edit-list-item-by-clicking-on.html . After some work with sharepoint designer 2010 I was able to mange it in few steps here as well . Here are the steps needs to be followed in this case:
1. Open the site in sharepoint designer.
2. Go to All Files.
3. Navigate down to the list where you want to do the modification.
4. Then open the view in sharepoint designer by double clicking on it in my case it was allitems.aspx.(Check it out first)
5. Now right click on the title part as shown in the screenshot below and select format hyperlink to Edit Form.















6. Save this file and you are ready to go.

I hope this will help you out.

Thanks,
Rahul Rashu

Saturday, 24 March 2012

How to edit a list item by clicking on its title in Sharepoint 2007

Hi,

I received a request from someone to modify a list view in such a manner that if some click on the title of the item it should take him to the edit page instead of display page. After some work with sharepoint designer I was able to mange it in few steps. Here are the steps needs to be followed in this case:
1. Open the site in sharepoint designer.
2. Navigate down to the list where you want to do the modification.
3. Then open the view in sharepoint designer by double clicking on it.
4. Now right click on the area of list viewer webpart and click the option to Convert to XSLT data view.
5. Now click on the section of title as shown





6. This will also select the portion in code part. There you will get a code portion as :
href="{$URL_Display}?ID={@ID}" onclick="GoToPage('{$URL_Display}?ID={@ID}')

7. Now just change it to:
href="{$URL_Edit}?ID={@ID}" onclick="GoToPage('{$URL_Edit}?ID={@ID}')
8. Save the page and you are ready to go.
9. Now if you click on title you will be taken to Edit form instead of dispform .

I hope this will help you out.

Thanks,
Rahul Rashu

Saturday, 3 March 2012

Your personal site cannot be created because the managed path "Path" has not been created for this site. Contact your site administrator for more information in Sharepoint 2010

Hi,

Recently one farm administrator reported a problem to me that they are unable to setup the mysites in SPS 2010 environment. They were following all the instructions in technet articles http://technet.microsoft.com/en-us/library/ee624362.aspx but still they were getting this error "Your personal site cannot be created because the managed path "Path" has not been created for this site. Contact your site administrator for more information". I suggested them to check if the managed paths are created and set up properly or not. They checked the same and found them OK. I suggested to create a new wildcard managed path and to test the same and they did so but their was nothing that could have caused this. At last I found the reason for it.

Under mysite settings their is field "Location". Here you need to add your managed path you have created for your mysites but you should only add its name and not with the full URL. So if you have created it as "Personal" it should be "Personal" only and not with the URL format as http://webApplication/mangedpath.

I asked them to change it and it worked.
I hope this will help you out.

Thanks,
Rahul Rashu

Sunday, 26 February 2012

One or more field types are not installed properly. Go to the list settings page to delete these fields in executing CAML queries

Hi,

An issues was reported to me where a developer was trying to use a  CAML query and was getting this error:
"One or more field types are not installed properly. Go to the list settings page to delete these fields". I checked the fields and they fine I executed few other queries and found that they were working fine. This was a clear indication that there was something wrong in the query rather than in the list settings. I found that the query had a column "Approval Status". To verify if it is causing the issue or not I executed  a small piece of code to get the internal name and I found that the internal name of this field is "_ModerationStatus". I changed the value in the query and it worked fine.

I am sharing this so that it will be helpful for someone facing this. I am attaching a small piece of code for reference


SPQuery query = new SPQuery();
                String camlQuery = "<Where><Eq><FieldRef Name='_ModerationStatus'/><Value Type='Text'>Pending</Value></Eq></Where>";
                query.Query = camlQuery;
                SPListItemCollection items = list.GetItems(query);

I hope this will help you out.

Unable to create a new Group in Manged Metadata Service in Sharepoint 2010

Hi,

An issue was reported to me where one of the farm administrator was not able to create a new group in managed metadata service in Sharepoint 2010. This looks strange to me since this involved very simple steps. I was able to overcome this within a minute and I am sharing it here so that others who will face this issue should not spend time on this. The drop down was not getting enabled in the left panel under managed metadata service node because the Term Store Administrator for this metadata service was not selected. I added this and then saved it . Now the drop appeared and "New Group" option started to come as shown in the image below:








I hope this will help you out.

Wednesday, 22 February 2012

The search request was unable to connect to the search service in Sharepoint

Hi ,

An issue was reported to me where in a new sharepoint environment the users were unable to search anything. Whenever they were trying to search they were getting this message "The search request was unable to connect to the search service in Sharepoint". I looked into the search settings and administration and found that it was fine. The files were also getting indexed and were available in crawl logs. I checked the account used for crawling and found that it was also fine. After some digging I found the solution to this problem. Here are the steps needs to be followed in this case:

1. Open Central Administrator
2. Go To Operations --> Services on server
3. Select the server you are using for query role.
4. Click on "Office Sharepoint Server Search".
5. Check the option "Use this server for serving search queries".
6. Provide credentials and check other settings and click on OK.

Thats it and it will work for you.

I hope this will work you out.

Thanks,
Rahul Rashu