“DropDownList has a SelectedIndex which is invalid because it does not exist in the list of items” error while setting SelectedIndex


I had my drop down list defined as following
<asp:DropDownList
ID=”ddlNeedEFMP” runat=”server” Enabled=”False”>
<asp:ListItem
Value=”2″>No</asp:ListItem>
<asp:ListItem
Value=”1″>Yes</asp:ListItem>

</asp:DropDownList>
To set it’s selectedindex we can make use of below syntax.

ddlNeedEFMP.SelectedIndex= ddlNeedEFMP.Items.IndexOf(ddlNeedEFMP.Items.FindByValue(“1”));

Hope it helps.

Some useful links while working with CSS.


Has some simple css for tables à

http://www.smashingmagazine.com/2008/08/13/top-10-css-table-designs/

Good site with live examples à

http://icant.co.uk/csstablegallery/tables/47.php

Setting CSS for disabled textbox à

http://www.cssportal.com/form-elements/text-box.htm

http://www.developertutorials.com/tutorials/html/styling-disabled-buttons-disabled-text-boxes-in-css-404/

Bye.

Exception message “entityName” in CRM 2011


Hi,

We get the “entityName” exception if we haven’t specified value for LogicalName property of Entity class. (easy to figure out 🙂 )
Hope it helps!

Using Bulk Data Export tool of CRM 4.0 with CRM 2011


We need to make following changes to get the Bulk Data Export tool for CRM 4.0(http://mscrmbulkdataexport.codeplex.com/workitem/list/basic) to work with CRM 2011.

Change the app.config of the tool

http://mscrmuk.blogspot.com/2011/02/using-crm-40-assemblies-on-crm-2011.html

<runtime>
<assemblyBinding
xmlns=urn:schemas-microsoft-com:asm.v1>
<dependentAssembly>
<assemblyIdentity
name=Microsoft.Crm.Sdk
publicKeyToken=31bf3856ad364e35
culture=neutral/>

<publisherPolicy
apply=no/>
</dependentAssembly>
</assemblyBinding>
</runtime>

And add references to the 64 bit version of Microsoft.crm.sdk and Microsoft.crm.sdktypeproxy dlls. (Which we can get from its SDK)

http://www.microsoft.com/downloads/en/confirmation.aspx?familyid=82e632a7-faf9-41e0-8ec1-a2662aae9dfb&displaylang=en

http://www.box.net/shared/z6z1dcby0k

Hope it helps.

Configuring Forms Based Authentication (FBA) for SharePoint 2010


Create a new web application from Central Administration.

Select Authentication as Claims Based Authentication

Check Enable FBA checkbox and specify Membership provider name and role manager name as SqlMembers and SqlRoles.

Click on Ok to create the web application.

After successful creation of the web application create a site collection.

Navigate to C:\Windows\Microsoft.NET\Framework64\v2.0.50727 and run aspnew_regsql.exe tool there.

Follow the screen shots below to create a new database named MYFBADB.

After successful creation of the database add the following information(highlighted in yellow) to the web.config file of our FBA application

<membership
defaultProvider=i>

<providers>

<add
name=i
type=Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c />

<add
connectionStringName=SqlConn
applicationName=/
name=SqlMembers
type=System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
minRequiredPasswordLength=5
minRequiredNonalphanumericCharacters=0 />

</providers>
</membership>

<roleManager
defaultProvider=c
enabled=true
cacheRolesInCookie=false>
<providers>
<add
name=c
type=Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c />

<add
connectionStringName=SqlConn
applicationName=/
name=SqlRoles
type=System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a />

</providers>
</roleManager>
</SharePoint>
<connectionStrings>
<add
name=SqlConn
connectionString=server=crm2011;database=MYFBADB;Trusted_Connection=true />
</connectionStrings>
<system.web>

Next open the web.config of the Central admin site and add the same information added above

<roleManager
enabled=true
defaultProvider=AspNetWindowsTokenRoleProvider>
         <providers>
             <add
connectionStringName=SqlConn
                 applicationName=/
                 name=SqlRoles
                 type=System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a/>
         </providers>
     </roleManager>

         <providers>
             <add
connectionStringName=SqlConn
                 applicationName=/
                 name=SqlMembers
                 type=System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a />
         </providers>     </membership>

</SharePoint>
    <connectionStrings>
        <add
name=SqlConn
connectionString=server=crm2011;database= MYFBADB;Trusted_Connection=true />

    </connectionStrings>    
<system.web>

Lastly add the following configuration information in the web.config file of the SecurityTokenServiceApplication (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebServices\SecurityToken)

    </system.net>
    <connectionStrings>
        <add
name=SqlConn
connectionString=server=crm2011;database= MYFBADB;Trusted_Connection=true />
    </connectionStrings>    <system.web>
        <membership
defaultProvider=SqlMembers>
            <providers>
                <add
connectionStringName=SqlConn
applicationName=/
name=SqlMembers
type=System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a />
            </providers>
        </membership>
        <roleManager
enabled=true
defaultProvider=SqlRoles>
            <providers>
                <add
connectionStringName=SqlConn
applicationName=/
name=SqlRoles
type=System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a/>
            </providers>
        </roleManager>
    </system.web>

That’s it.

Adding User to SharePoint Group through a custom ASP.NET web service.


I had a requirement to create a web service which would be used to add user to a SharePoint group. The code for it

[WebMethod]
public  string AddSharePointUser(string username,string password, string email){
string statusInfo = “”;
try
{
s
tring SharePointUrl = ConfigurationManager.AppSettings[“SharePointUrl”].ToString();
string SharePointGroup = ConfigurationManager.AppSettings[“SharePointGroup”].ToString();

SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite oSiteCollection = new
SPSite(SharePointUrl))
{
oSiteCollection.AllowUnsafeUpdates = true;
using (SPWeb oWebsite = oSiteCollection.OpenWeb())
{
oWebsite.AllowUnsafeUpdates = true;
SPUser spUser = oWebsite.EnsureUser(username);

SPGroup spGroup = oWebsite.SiteGroups[SharePointGroup];

spGroup.AddUser(spUser);
oWebsite.AllowUnsafeUpdates = false;

}

oSiteCollection.AllowUnsafeUpdates = false;

}});

statusInfo = “User Created Successfully”;

}
else
{
statusInfo = “User Already Exists”;

}}
catch (Exception ex)
{
statusInfo = ex.Message;

}
return statusInfo;

}

To run the web service successfully, we need to set the identity of application pool of the web service to SharePoint Administrator account.

Hope it helps.