Wednesday 25 January 2012

How to setup alerts on User Information List in Sharepoint

Hi,

I got a request where a site collection administrator wanted to track the changes in "User Information List" without using any custom code. The very first way is to enable auditing under site collection administration for "Editing users and permissions". However this will fill the database and will result in performance issues. So this was not acceptable to the site administrators. Moreover his requirement was to track only when a user is added or removed from site collection. Hence we approached to setup the alerts.

When we reached to the User Information List we do not find any option to setup alerts or go to setting etc as normal lists.

Now we used the following method to get it through:
1. Our first requirement was to get the GUID. To get this we queried dbo.Lists table in the content database holding this site collection.
2. The query should be:
Select tp_ID From Lists with(NoLock)where tp_Title = 'User Information List'
3.Make a note of this ID.
4. Now go to any other list in the top site in your site collection and click on Alert Me under Actions.
5. In the next page in URL remove the contents after ?List= and add the GUID noted in step 3.
6. Press enter and now you will find that the fields are populated with User Information List and you can create the alerts.

I hope this will help you out.

Thanks,
Rahul Rashu

Sunday 8 January 2012

Access Denied By Business Data Connectivity Error in Using External Content Type List in Sharepoint 2010

Hi,

Recently an issue was reported to me where a site administrator tried to use a table in sql server as an external content source. He was able to create the external content type based on this and had defined all CRUD operations. He also created a list based on this external content type however when he was trying to access this list he got this error:











This was throwing an access denied error message by Business Data Connectivity. It was a clear indication of the problem and I resolved this by following steps:

1. Login into central administrator and click on "Manage Service Applications"











2.  Now click on Business Data Connectivity Services :












3. Now check the External Content Type that was created and click on Set Object Permissions:











4. Now add the user and grant permissions as shown and click OK and you are ready to go:



I hope this will help you out:

Thanks,
Rahul Rashu

How to upload a folder and containing files into a sharepoint document library using client object model

Hi All,

I received a recent request to provide a tool to upload documents from a local machine to sharepoint document library using client object model in SPS 2010. I have selected the managed code model to do it.
This tool takes 3 inputs:
1. The URL of the sharepoint site where the library is located.
2. The name of the document library.
3. Path of the folder in your local machine.

If the folder does not exists it will create a new folder and if the files already exists it will overwrite them.
Here is the code:

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

namespace TestClientManagedCode
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("This tool will copy the entire folder from your local machine to the sharepoint document library");
            Console.WriteLine("Please enter the url of the site");
            String siteUrl = Console.ReadLine();
            Console.WriteLine("Please enter the name of the document library");
            String dLibraryName = Console.ReadLine();
            Console.WriteLine("Please enter the full path of the folder containing the files without the filname");
            String folderPath = Console.ReadLine();
            try
            {
                using (ClientContext ctx = new ClientContext(siteUrl))
                {
                    Web web = ctx.Web;
                    ctx.Load(web);
                    ctx.ExecuteQuery();
                    List dUplaod = web.Lists.GetByTitle(dLibraryName);
                    String[] fileNames = Directory.GetFiles(@folderPath);
                    bool exists = false;
                    DirectoryInfo dInfo = new DirectoryInfo(@folderPath);
                    FolderCollection folders = dUplaod.RootFolder.Folders;
                    char[] sep = { '\\' };
                    ctx.Load(folders);
                    ctx.ExecuteQuery();
                    foreach (Folder eFolder in folders)
                    {
                        if (eFolder.Name.Equals(dInfo.Name))
                        {
                            foreach (String fileName in fileNames)
                            {

                               
                                String[] names = fileName.Split(sep);
                                FileCreationInformation fCInfo = new FileCreationInformation();
                                fCInfo.Content = System.IO.File.ReadAllBytes(fileName);
                                fCInfo.Url = names[names.Length - 1];
                                eFolder.Files.Add(fCInfo);
                                exists = true;
                            }

                        }
                    }

                    if (!exists)
                    {
                        Folder tFolder = folders.Add(siteUrl + "/" + dLibraryName + "/" + dInfo.Name);
                        foreach (String fileName in fileNames)
                        {


                            String[] names = fileName.Split(sep);
                            FileCreationInformation fCInfo = new FileCreationInformation();
                            fCInfo.Content = System.IO.File.ReadAllBytes(fileName);
                            fCInfo.Url = names[names.Length - 1];
                            tFolder.Files.Add(fCInfo);
                        }
                    }
                   
                    ctx.ExecuteQuery();
                    Console.WriteLine("The Execution is completed");
                    Console.ReadLine();

                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }

        }
    }
}


I hope this will help you out.

Thanks,
Rahul Rashu