Attempted to perform an unauthorized operation – Error while updating other user’s profile data in Sharepoint 2010

We had a requirement where a user profile property will be updated from the event receiver of a custom list. The user profile property which we can had “user can override” and “Allow users to edit”, however we were getting an error “Attempted to perform an unauthorized operation”

The code was running under RunWithElevated delegate. We traced the user id which was Sharepoint\System. The system account in use will be the App pool Identity under which the current Sharepoint site is running. We took app pool identity id and gave full permission for user profile service application. This didn’t solve our problem.

Solution:

Get the App pool identity, of the Sharepoint site from IIS.

Go to Sharepoint Central Admin > Application Management > Manage Service Application.

Select the User Profile Service Application which is associated to your site, and select Manage Permission from top ribbon. Add the App Pool Id and give full control.

Then select Administrators in the TOP ribbon for User Profile service application and add the app pool identity id and give full control.

 



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Block Application pages and Form Pages in Sharepoint 2010

By default Sharepoint doesn’t blocks user with limited access from visiting application pages (for ex _layouts/viewlsts.aspx).

Someone who knows the URL, can go to this page.

 We can avoid this by change the limited access to lockdown mode. Use the command below.

  

Action

Command

Turn on lockdown mode for a site collection

stsadm -o activatefeature -url <site collection url> -filename ViewFormPagesLockDown\feature.xml

Turn off lockdown mode for a site collection

stsadm -o deactivatefeature -url <site collection url> -filename ViewFormPagesLockDown\feature.xml

For more info on this visit http://technet.microsoft.com/en-us/library/cc263468(office.12).aspx#section6 

 

 Once locked down mode is enabled, groups/users with View Application pages will only be able to visit these pages. You can either select Restricted Read permission or remove View Application Pages permission for the users or groups which you want to block application pages.



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

ULS Tracelog To WSS_Logging Database in Sharepoint 2010

By Default ULS trace logs are logged to text file in 14 Hive\LOGS. In sharepoint 2010 we have a provision to move these logs to WSS_Logging database.  Follow these steps to get ULS tracelogs to WSS_Logging Database.

 

  1. Open the SharePoint Central Administration site

  2. Navigate to the Monitoring section

  3. Select Review Job Definitions

  4. Click on the job with the name Diagnostic Data Provider: Trace Log

  5. Click on the Enable button to enable it

  6. Click on Run Now, to start it immediately

     

 



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Add Team Site Under Publishing Site as a Subsite

By default when you try create a subsite under a Publishing site with will give you only 2 options. (Publishing Site or Enterprise Wiki).

But we can enable as many site templates as we want. Go to Site Actions > Site Settings > Look And Feel > Page Layout and Site template.

Select the list of templates you want.

 



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Accessing Interop dlls makes winforms exes non responsive

In one of my windows application, I was making use of Domino inerop for accessing document data from lotus notes. Whenever the interop was probed for some bigger response, my application use to be non responsive or hang.Once the call to inerop is done the application was accessible. Users will not know the progress in such scenarios.

You can avoid this by introducing a Background thead. Move all the inerop method calls to a seperate function. On you event handler add a background thread and call the function.

Thread newThread = new Thread(FunctionWithInteropCalls);

newThread.IsBackground = true;

newThread.Start();

If the thread is marked as a Background thread, the thread will be killed automatically during Application.Exit()

Now if function which is executed by newThread should access windows objects created in the main thread, you will have to handle it. Sample below shown how you can achieve this.

public void AccessMainThreadObj(string value)
{
if (InvokeRequired
{
this.Invoke(newAction<string>(AccessMainThreadObj), value); 
return;
}
if(value.StartsWith("#1"))
    textbox1.Text = value.Substring(2);
else
   richTextBox2.Text += value;
}
  
 
void FunctionWithInteropCalls()
{
AccessMainThreadObj("#1 To update textbox1");
AccessMainThreadObj("To update richTextBox2");
}
 

 Create a method to update the value of the controls in the form. Basically this function checks whether the current process needs an invoke, if yes comes through the builtin invoke method.

 

 



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Enums in C# - To get text value from corresponding number

Enums are always a favourite when we want to restrict users while sending some string to a generic methods. Was exploring how to get the text of the enum from the correspoing number. .Typecasting the number to the enum type would get the text from enum. Have shared a sample on this

Using System;

namespace ConsoleApplication1 {

class Program{

enum WeekDays { Sun = 1, Mon = 2, Tue, Wed, Thu, Fri, Sat }

staticvoid Main(string[] args) {

Console.WriteLine(((int)WeekDays.Thu).ToString());

Console.WriteLine(((WeekDays)1).ToString());

Console.Read();

}}}

Output :

5

Sun



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Updating Mutliselect CheckBox columns in sharepoint 2010 using SPClientCotext

In one of my project we had a scenario where we have to update a multi select choice column in sharepoint list from out client application. The asp.net way of comma seperated way was tried but didnt work for us. After lot of trial and error we found that the value should can updated as a string array.

oList["MultiChoiceColeName"] = new string{"FirstVal", "ThirdVal", "lastVal"};



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Lotus Notes Interop to connect from dotnet application to Lotus Notes Database

While connecting to Lotus notes database from dotnet application using Interop.Domino dll, I was getting the following error.  (“Retrieving the COM class factory for component with CLSID {29131539-2EED-1069-BF5D-00DD011186B7} failed due to the following error: 80040154”)

When i installed Domino Server setup we the issue was solved. But unforunately this will not roll out as we might have to run the migration application in different machines. After searching a lot i net i found an article in IBM site about a dll named nlsxbe.dll.

Once I registered this dll using regsvr32, i was able to connect to lotus database with just lotus client installation and Interop.Domino object.

nlsxbe.dll will be found in lotus notes installed folder. 

More to come on lotus notes migration, watch this space.



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Powersheel script to Clear all Items in Sharepoint List

The below given powershell script will clear all items in a list. You should use powershell IDE to run this script.

 

[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")

$siteObj = new-object Microsoft.SharePoint.SPSite ( "http://yousiteurl" )
$SPweb = $siteObj.OpenWeb()
"Web is : " + $SPweb.Title

$oList = $SPweb.Lists["you list name"];

$oList.Title + " : Total Items Count is " + $oList.ItemCount

$collListItems = $oList.Items;
$count = $collListItems.Count - 1

for($intIndex = $count; $intIndex -gt -1; $intIndex--)
{
        "Deleting : " + $intIndex
        $collListItems.Delete($intIndex);
}

 

 

 



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Getting Distinct Column Values from a (C#)Datatable

The following code snippet shows you a way to extract distinct values in a specific column from a datatable.
 
            // Datatable Creation
            DataTable dt = new DataTable();
            DataColumn dc = new DataColumn("Col1");
            dt.Columns.Add(dc);
            dc = new DataColumn("Col2");
            dt.Columns.Add(dc);
 
 
            DataRow dr = dt.NewRow();
            dr[0] = "A1";
            dr[1] = "B1";
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr[0] = "A1";
            dr[1] = "B2";
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr[0] = "A1";
            dr[1] = "B3";
            dt.Rows.Add(dr);
 
           // To Copy distinct values from col1 to a different datatable
            DataTable uniqueCols = dt.DefaultView.ToTable(true, "col1");
 
 
We have got disctinct values of  col1 into uniqueColTable. DefaultView.Totable can accept more than one column. The first parameter indicates that the method should fecth disinct values. you can also write dt.DefaultView.ToTable(true, "col1","col2"); which will fecth distinct values from both the column combination and copy that to new datatable.


  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati