Sunday 30 December 2012

Visio Web Access is not available on this site

Hi,

An issue was reported to me where some of my site administrators were unable to use Visio web access webparts after configuring Visio Graphics service application in central administrator. After adding the Visio web access webpart in a page an error was getting displayed as "Visio Web Access is not available on this site".

I quickly found a solution for it as activation of the feature ""SharePoint Server Enterprise Site Collection features" at site collection level and also the activation of the feature "SharePoint Server Enterprise Site features" at site level.

I hope this will help you out.

Thanks,
Rahul Rashu
 

Saturday 27 October 2012

How to Programmatically Approve documents in Sharepoint

Hi,

A requirement was posted to me where a developer wanted to approve the documents programmatically. I shared the code snippet below and it the logic worked out. I am sharing it here again:

using
(SPSite site = new SPSite("YourSiteUrl"))

{
using(SPWeb web = site.OpenWeb())

{
SPFolderCollection folders = web.Folders;

SPFolder folder = folders["DocumentLibraryName"];

SPFile file = folder.Files[itemIndex];

file.CheckIn("CheckInComment", SPCheckinType.MajorCheckIn);

file.Approve("Approved");

web.Update();

}

}

This code snippet can be modified in the way desired.

Thanks,


Rahul Rashu
 

Saturday 8 September 2012

How to find the size of a subsite in Sharepoint 2010

Hi,

Recently a requirement was posted with me where the site administrators wanted to determine the size of their subsites as well and not only for the entire site collection or content database. The size of the content database can be determined easily and same for the site collection. However there was no direct way for the subsites. Hence I had to find out an alternative way for the same and after some research I found a way. The steps are as below:
1. Open any document library of the site which is one level up in site hierarchy for the subsite in concern.
2. In the ribbon select Library--> Open with Windows Explorer.
3. Now a windows explorer will open pointing to that document library. Now navigate to the site level.
4. This will show all the folder available under the site select the folder that corresponds to your site subsite in concern.
5. Right click and select properties. This will display the size.

I hope this will help you out.

Saturday 11 August 2012

Powershell Script to list of the documents checked out with version details in a site collection in Sharepoint

Hi,

I received a recent requirement to create a report that provides the details of checked out items in an entire site collection. This report should also contain data for the person whom the document is checked out to. It should also provide the version and if no version exists it should mention the same.

So after playing with powershell for some time I prepared a script that works in exactly the same way.
If you want to extract this report to some .csv file then you need to provide this at the time of invoke itself.
For example:-  .\ScriptName.ps1 >FileName.csv
During the execution it will ask for the site url which you need to provide. It works with both Sharepoint 2007 and Sharepoint 2010 versions.




[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

function CheckedOutItems() {

write-host "Please enter the site url"
$url = read-host
write ("SiteURL`t" + "FileName`t" +  "CheckedOutTo`t" + "ModifiedDate`t"+"Version")
$site = New-Object Microsoft.SharePoint.SPSite($url)
$webs = $site.AllWebs
foreach($web in $webs)
{
$listCollections = $web.Lists
foreach($list in $listCollections)
{


if ($list.BaseType.ToString() -eq "DocumentLibrary")
{
 $dList = [Microsoft.Sharepoint.SPDocumentLibrary]$list
 $items = $dList.Items
$files = $dList.CheckedOutFiles
foreach($file in $files)
{

$wuse = $file.DirName.Substring($web.ServerRelativeUrl.Length)
Write ($web.Url+ "`t" + $wuse+"`/" + $file.LeafName +  "`t" + $file.CheckedOutBy.Name + "`t" + $file.TimeLastModified.ToString()+"`t" + "No Checked In Version" )
}
 foreach($item in $items)
 {
 if ($item["Checked Out To"] -ne $null)
  {
$splitStrings = $item["Checked Out To"].ToString().Split('#')

  Write ($web.Url+ "`t" + $item.Url + "`t" + $splitStrings[1].ToString() + "`t" + $item["Modified"].ToString() +"`t" + $item["Version"].ToString())
 }
 }


}



}
$web.Dispose()
}
$site.Dispose()
}


CheckedOutItems


I hope this will help you out.

Thanks,
Rahul Rashu

Monday 16 July 2012

How to embed flash files into Sharepoint site peges

Hi,
Recently a requirement was posted to me where a site admin wanted to use some flash files on some of the pages in his site. After some initial look here are the steps followed:

1. The flash file was uploaded to a document library.
2. In the page where he wanted to show the flash file a content editor webpart was added to the webpart zone
3. The following script was added into the source editor to get it worked.
<Embed src="RelativeUrlToFlahFile" TYPE="application/x-shockwave-flash" width="700" height="200"></Embed>

The parameters above are self explanatory and can be changed based upon requirements. This works in both MOSS 2007 and SPS 2010.
I hope this will help you out.

Thanks,
Rahul Rashu

Thursday 28 June 2012

How to embed PDF and text file contents in sharepoint pages

Hi,

I was presented a requirement where some of the site administrators wanted to show contents from PDF and text files to many pages in our sharepoint sites. The content was either text or images. There is always a way to add this under the page controls and pods but it was not an effective way of doing so since for any change in the requirement it has to be carried out in all pages manually. Hence I used the content editor webpart to display the text. The file was stored in a document library and it was being referred by my content editor webpart so any changes in the file will be reflected in my pages as well. To refer the file in my content editor webpart I used the following script in source editor of my webpart :


<iframe width="560" height="345" src="FileUrl" frameborder="0" ></iframe>


Thats it and it worked out


I hope this will help you out.


Thanks,
Rahul Rashu


Thursday 14 June 2012

How to delete a timer job using powershell in sharepoint

Hi,
Recently many site admins requested me to provide an easy way to delete a timer job. A timer job can always be deleted via a non documented STSADM command as
STSADM -o deleteconfigurationobject -id guid. However this command is not recommended for production environment. Hence to resolve this issue I created a powershell script that takes only one input as the guid of the timer job and deletes it. Here is the script :

param([string]$jobid)

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")


function RahulDeleteTimerJob($jobid) {

write-host "This script will delete a timer job"
        $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
        $services = $farm.Services
        foreach($service in $services)
{

$jobdefs = $service.JobDefinitions
foreach($job in $jobdefs)
{
       if($job.Id.ToString() -eq $jobid)
{

          $job.Delete()

}

}

}

write-host "The job is deleted"

}

RahulDeleteTimerJob $jobid




I hope this will help you out.

Thanks,
Rahul Rashu

Tuesday 5 June 2012

How to Hide Columns in list forms in sharepoint without using Sharepoint designer

Hi,

Recently a requirement was posted to me where the end users wanted to hide columns in list forms without using sharepoint designer. Our site admins can do this easily using sharepoint designer but since there were many lists and requests so it was not possible to go to each and every one and carry out this task manually. Hence I created a tool using C#. This works in both MOSS 2007 and SPS 2010.This takes three inputs:
1. The complete List URL. ex: http://webApplication/Site/Lists/ListName/Allitems.aspx. (Note:- The URL upto any view can be used here).
2. The field name that is to be hidden.
3. 1 ,2 or 3 based on the requirement as these numbers stands for "1 for EditForm, 2 for DisForm and 3 for NewForm".

On successful completion it will show a message that the execution is completed.
Here is the code to do this:


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

namespace HideFieldInListFormRahul
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("This tool will hide a field from list forms. It requires List Url and field URL");
                Console.WriteLine("Please enter list URL");
                String listUrl = Console.ReadLine();
                Console.WriteLine("Please enter column name");
                String columnName = Console.ReadLine();
                Console.WriteLine("Enter 1 for EditForm, 2 for DisForm and 3 for NewForm");
                String formType = Console.ReadLine();
                using (SPSite site = new SPSite(listUrl))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        String listRel = listUrl.Substring(web.Url.Length);
                     
                        SPList list = web.GetListFromUrl(listUrl);
                        SPField field = list.Fields[columnName];
                        if (formType.Trim().Equals("1"))
                        {
                            field.ShowInEditForm = false;

                        }
                        else if (formType.Trim().Equals("2"))
                        {
                            field.ShowInDisplayForm = false;
                        }
                        else if (formType.Trim().Equals("3"))
                        {
                            field.ShowInNewForm = false;
                        }
                        else
                        {
                            Exception ex = new Exception("No Proper number between 1 to 3 has been entered");
                            throw ex;
                        }
                        field.Update();
                        Console.WriteLine("The execution completed.Press Enter to Exit");
                        Console.ReadLine();
                    }
                }

            }

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

I hope this will help you out.
Thanks,
Rahul Rashu

Sunday 3 June 2012

An error was encountered while retrieving the user profile in Sharepoint 2010

Hi,

An issue was reported to me where some of the developers were facing some issues in executing the code to get user profile in sharepoint 2010. The exception was following:

Microsoft.Office.Server.UserProfiles.UserNotFoundException was unhandled
  Message=An error was encountered while retrieving the user profile.
  Source=Microsoft.Office.Server.UserProfiles
  StackTrace:
       at Microsoft.Office.Server.UserProfiles.UserProfileCache.GetUserData(UserProfileManager objManager, Nullable`1 recordId, Guid gAcct, String strAcct, Byte[] bSid, String strEmail, Boolean doNotResolveToMasterAccount)
       at Microsoft.Office.Server.UserProfiles.UserProfile.RetrieveUser(String strAcct, Guid gAcct, Byte[] bSid, Nullable`1 recordId, Boolean doNotResolveToMasterAccount, Boolean loadFullProfile)
       at Microsoft.Office.Server.UserProfiles.UserProfile..ctor(UserProfileManager objManager, String strAcct, Boolean doNotResolveToMasterAccount, Boolean forceUserIsSelf, Boolean loadFullProfile)
       at Microsoft.Office.Server.UserProfiles.UserProfileManager.GetUserProfile(String strAccountName, Boolean doNotResolveToMasterAccount, Boolean loadFullProfile)
       at Microsoft.Office.Server.UserProfiles.UserProfileManager.GetUserProfile(String strAccountName, Boolean doNotResolveToMasterAccount)
       at Microsoft.Office.Server.UserProfiles.UserProfileManager.GetUserProfile(String strAccountName)
       at WelcomeControlModification.Program.Main(String[] args)

This exception was originating from this line of code:

UserProfile userProfile = manager.GetUserProfile("Domain\userName");

We checked the domain as well as the userName and found no issues with that. We even checked the permissions of the ID executing the code. Finally a small modification based on my experience with Sharepoint 2007 solved this issue we just replaced

UserProfile userProfile = manager.GetUserProfile("Domain\userName");

With

UserProfile userProfile = manager.GetUserProfile("Domain\\userName");

In short we just added an additional \ as a escape sequence.
This resolved our issue.

I hope this will help you out.

Thanks,
Rahul Rashu


Saturday 19 May 2012

The Web server at URL does not appear to have Microsoft SharePoint Foundation installed in Sharepoint 2010

Hi,
Recently one issue was reported to me where some of the administrators reported that they were unable to use sharepoint designer and while trying to open the sites they were getting the message "The Web server at URL does not appear to have Microsoft SharePoint Foundation installed". The site was functioning well with all capabilities in browser. I noticed that these all sites were hosted under a specific wen application so it was a clear indication that there was something wrong at web application level. After few initial investigation I managed to get it resolved. Here are the steps followed:
1. Login into the Central Administrator.
2. In the main page click on Security option in left hand navigation.
3.In the next page select the web application hosting your sites.
4. Click on default--> Check the option of enable Client Integration.

Thats it and now the sites can be accessed in sharepoint designer as well.
 I hope this will help you out.

Thanks,
Rahul Rashu

Tuesday 8 May 2012

Using Themes from Office Suites in Sharepoint 2010 Sites


One of a common requirement now a days is to apply customized branding and look to any site. With businesses growing daily there is significant use of this.
The process of changing themes in Sharepoint 2010 is much simpler than that of 2007. Now you can create your themes in other office suites like powerpoint and can apply the same here in sharepoint. These themes are created with .thmx extension and can be uploaded to your site before use. In this we will use an existing theme from Powerpoint 2010 in our site.
You can use an existing one or can design one by opening powerpointà File à New à Theme







Once you have designed the theme save it. It will be saved in .thmx extension.
Now open your sharepoint site àSite Settings àGo TO Top Level Site Settings(If it is a subsite)à Gallery à Theme. This will open the theme gallery as shown below:




Click on Add new item and upload your saved .thmx file.
Now go to your site settings and under look and feel click on themes and apply your created one.
I hope this will help you out.
Thanks,
Rahul Rashu

Thursday 12 April 2012

How to Apply Unique value Constraint in Person and Group column in Sharepoint 2010

Hi,
Recently an issue was reported to me where one of the site admin was unable to apply uniqueness in a column of type Person or Group in a list. When he was trying to create a column of that kind he was getting a screen like this:











In the above screenshot there is no possibility to enforce uniqueness. Hence the next approach was to do this pro grammatically. In case of Sharepoint 2007 this would have required creating an event receiver or workflow that could have checked uniqueness . However in case of Sharepoint 2010 a property "EnforceUniqueValues" on SPField that can be marked as true and it will work out. However we need to be sure that there should not be any existing values in the list violating this constraint or else this will fail. We also need to be sure that this should get applied only on indexed column. Hence I have ensured this in the code itself.

Here is the code for this:


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Microsoft.SharePoint;

namespace EnforceUniqueness

{

class Program

{

static void Main(string[] args)

{

try

{

Console.WriteLine("This tool will apply unique value constratint to a column in a list. Make sure that your list does not contain duplicate values in this column");

Console.WriteLine("\n");

Console.WriteLine("Enter the URL of Your Site");

String siteUrl = Console.ReadLine();

Console.WriteLine("Enter the Name of List name");

String listName = Console.ReadLine();

Console.WriteLine("Enter the Column Name");

String columnName = Console.ReadLine();

using (SPSite site = new SPSite(siteUrl))

{

SPWeb web = site.OpenWeb();

SPList list = web.Lists[listName];

SPField field = list.Fields[columnName];

field.Indexed = true;

field.EnforceUniqueValues = true;

field.Update();

Console.WriteLine("Tool Executed successfully. Press Enter to Terminate");

Console.ReadLine();

}

}

catch (Exception e)

{

Console.WriteLine(e.Message + "\n"+ e.StackTrace);

Console.ReadLine();

}

}

}

}

The execution will follow in this way:














I hope this will help you out.

Thanks,
Rahul Rashu

Sunday 8 April 2012

A Content Type Which Does Not Belong To A Collection Cannot be Updated In Sharepoint

Hi,

An issue was reported to me where a content type was not getting created programmatically. Whenever through code columns were added to it it was throwing the exception "A Content Type Which Does Not Belong To A Collection Cannot be Updated".  I did a walk through of the code and found that through code first a new content type was instantiated and then some columns were added to this. Here is the place where the exception was originating.

I referred some articles in MSDN and found out the reason for it. The reason was that although the content type was instantiated it was not added to any collection or in other words it was not associated with any site.
Hence we added following lines of code before calling update method and it became successful.

SPWeb web = site.OpenWeb();
web.ContentTypes.Add(MyContentType);

I hope this will help you out.

Thanks,
Rahul Rashu



Saturday 7 April 2012

Not Available locally Error while Executing Configuration Wizard in Sharepoint 2010


Hi,

Recently an issue was reported to me where execution of sharepoint configuration wizard was failing for addition of a server in an existing farm with the error message "Not Available locally". This was failing just at the step where the  connection to existing configuration database is carried out. The logged in user had all necessary rights including them in admin and content database. After some initial investigation I though of starting the wizard as an administrator option by right clicking on it and selecting "Run As Administrator". We did it and thats it it worked.

I hope this will help you out.

Thanks,
Rahul Rashu

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

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