Filtering list items in SharePoint based on current user and current user groups

Of late, I was working on a list view where I’ve to filter the items based on the current user and the current user groups. Filtering the items by the current user is a straight forward approach where you can select the user field and set the value to [Me]. But there is no provision in the list view filter page where you can filter the items based on the group specified in the field.

But with the help of designer you can manually edit the CAML of the XSLT list viewer webpart in the view page and use the Membership element to filter based on the group. All you have to do is to use CurrentUserGroups as the membership type to show that particular item for the users in that specified group.

<Or>
  <Membership Type=\"CurrentUserGroups\">
    <FieldRef Name=\"AssignedTo\"/>
  </Membership>
  <Eq>
    <FieldRef Name=\"AssignedTo\"></FieldRef>
    <Value Type=\"Integer\">
      <UserID/>
    </Value>
  </Eq>
</Or>

Let’s consider that an item has the filed value as “Kate, John; Approvers”. The item will be shown to the user John kate as well as the members of the group ‘Approvers’. Remember that you have to set the people or group field to allow multiple values as well as selecting objects from SharePoint groups to hold such a value.

Using CommonShowModalDialog in SharePoint

I’ve not found any post explaining the usage of CommonShowModalDialog in SharePoint, the default popup used by SharePoint across the board. So I thought why can’t I make one.

The method exists in core.js and it is used OOTB by SharePoint for opening popups in places like selecting a web application from a list of web applications, selecting a site collection from a list of site collections etc. (you could see these in Central administration). So here is the method –

function openPopup(){
    commonShowModalDialog("/_layouts/selectitem.aspx", "resizable: no; status:no; scroll: no; help: no; center: yes; dialogwidth:410px; dialogHeight:300px;", RetrieveItemValue);
}

CommonShowModalDialog has similar parameters as a simple window.open().

  1. Target URL
  2. Window features
  3. Callback function

To pass a value from the popup to the parent page use window.returnValue in te popup to save the value before closing the window.

//called from the popup page
function closePoup(){
    window.returnValue = myValue;
    window.close();
}

Retrieve the value passed from the popup in the callback function mentioned.

//Retreives the value sent from the popup
function RetrieveItemValue(retValue) {
    alert(retValue);
}

As simple as that.

IIS going blank in a SharePoint 2007 server

Hello

Are you puzzled to see your IIS opening up blank not showing any of your sites? Is SharePoint server 2007 installed in the server? If yes, the issue is because of overloaded thread requests on your IIS. I suspect this has something to do with the WSS timer service. Not sure though. To get back your IIS just do an IISRESET in the box. And there you’ll get all your sites back in IIS.

Adding Web User Controls (.ascx) to WSPBuilder Project

I was working on a SharePoint webpart in Visual Studio 2005,  few days before, creating a WSPBuilder project. At one stage i wanted to add a web user control (.ascx file) to my project and make use of it in my webpart. So i right clicked the appropriate folder i want to place it in the 12 hive and chose add new item.

But i was not able to see a Web User Control item in the list of Add New Items. I tried a few items to add the item and then thought of an ugly idea of creating the ascx in another project and copying it into this project. Then i got this solution from an online article for adding web application items support to the wspbuilder project.

1. Right click the project and choose ‘Unload Project’ from the menu.

2. Right the project node in Solution Explorer and choose Edit ProjectName.csproj.

3. Look for the highlighted line in the .csproj file.

2 <PropertyGroup>

3 <Configuration Condition= ‘$(Configuration)’ == ” >Debug</Configuration>

4 <Platform Condition= ‘$(Platform)’ == ” >AnyCPU</Platform>

5 <ProductVersion>8.0.50727</ProductVersion>

6 <SchemaVersion>2.0</SchemaVersion>

7 <ProjectGuid>{375819D3-5E9F-41ED-B8A5-2888B82C2539}</ProjectGuid>

8 <OutputType>Library</OutputType>

9 <AppDesignerFolder>Properties</AppDesignerFolder>

10 <RootNamespace>SampleWSP</RootNamespace>

11 <AssemblyName>SampleWSP</AssemblyName>

12 <ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

13 <SignAssembly>true</SignAssembly>

14 <AssemblyOriginatorKeyFile>SampleWSP.snk</AssemblyOriginatorKeyFile>

15 <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>

16 </PropertyGroup>

4. Add {349c5851-65df-11da-9384-00065b846f21} to the ProjectTypeGUIDs node.

2 <PropertyGroup>

3 <Configuration Condition= ‘$(Configuration)’ == ” >Debug</Configuration>

4 <Platform Condition= ‘$(Platform)’ == ” >AnyCPU</Platform>

5 <ProductVersion>8.0.50727</ProductVersion>

6 <SchemaVersion>2.0</SchemaVersion>

7 <ProjectGuid>{375819D3-5E9F-41ED-B8A5-2888B82C2539}</ProjectGuid>

8 <OutputType>Library</OutputType>

9 <AppDesignerFolder>Properties</AppDesignerFolder>

10 <RootNamespace>SampleWSP</RootNamespace>

11 <AssemblyName>SampleWSP</AssemblyName>

12 <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

13 <SignAssembly>true</SignAssembly>

14 <AssemblyOriginatorKeyFile>SampleWSP.snk</AssemblyOriginatorKeyFile>

15 <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>

16 </PropertyGroup>

5. Now right click the Project and choose ‘Reload Project’ and try adding a .ascx file.

You must get it now.

Note: Cross posted – http://blog.sharepointpowerpack.com/archive/2010/11/22/adding-web-user-controls-ascx-to-wspbuilder-project.aspx

NLV

Cannot save the property settings for this Web Part. Exception occurred. (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))

Hi all,

I was working with a webpart in MOSS and I created my custom toolpart for configuring the web part. Once, when I was trying to save the settings, I got the error – “Cannot save the property settings for this Web Part. Exception occurred. (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))”. I was confused and when I tried to debug the webpart I was not hit by any exceptions.

After crawling through some articles I found that I was disposing the SPWeb and SPSite objects which stores the current context of the site. So I removed all the code disposing the SPWeb and SPSite objects STORING THE CURRENT CONTEXT OF THE SITE (you have to dispose the usual SPSite and SPWeb objects with Using statements or disposing them in the ‘finally’ blocks). And bingo, it worked.

You may also get the following error

"Trying to use an SPWeb object that has been closed or disposed and is no longer valid."

while trying to add a webpart.

So never dispose those objects when they belong to the current context.

Me

Hitting 401 – Unauthorized for FBA enabled sites in SharePoint

Among the multitude of issues I faced in the process of creating an internet facing publishing portal in SharePoint, this one was killing me for a couple of days.

After extending my web application to intranet zone, i enabled FBA authentication with anonymous access in my default zone. The strange thing i noticed is that if you open a page for the first time, you’ll hit a page showing 401 – Unauthorized error. But if you refresh the page in your browser, the page loads fine in anonymous mode. Each and every ‘postbacks’ in your pages will face the same issue. After hours of googling and found the solution for the problem. To get rid of the issue

1. Change <compilation batch=”true” debug=”true”> to <compilation batch=”false” debug=”false”> in your web.config.

2. Allow anonymous access in the windows authentication zone. To do that follow these steps.

  • Go to Central Administration -> Application Management -> Authentication Providers
  • Select your web application
  • Choose the appropriate zone which is configured to use windows authentication
  • Check ‘Allow anonymous access’
  • Click OK

Whoomp! The issue is gone.

Delete Extended Web applications in SharePoint

I was in the process of migrating a MOSS publishing site to a production server. I extended the site to intranet zone to have the default zone to be configured for FBA authentication. While extending the site I made a typo while specifying a host header for the site. When I tried to delete the extended web application by selecting it from the web applications list in CA I was not able to find the extended application’s entry. Then I googled for a while to find a solution and found it here – http://sharepointnotes.wordpress.com/2008/07/17/quick-tip-delete-extended-web-application/.

To delete an extended web application,

1. Go to Central Administration -> Application Management -> Remove SharePoint from IIS Web Site

2. Select the original web application from the list

3. Select the appropriate extended application to delete

4. Press OK