Monday, November 28, 2011

The requested database does not have provider name set in the connection string

Hello Friends

I came across with an error when I was trying to connect to SQL Database by using Microsoft.Practices.EnterpriseLibrary.Data

It throws below error every time.
“The requested database <databasename> does not have provider name set in the connection string."

Then I checked the connection string in web.config file of SharePoint WebApplication and I found that this parameter is missing “providerName="System.Data.SqlClient" in the <ConnectionString> tag.

Old Connection string:
<connectionStrings>
    <add connectionString="Server=servername;Database=dbname;User ID=userid;Password=password" name="MyConnectionstring" />
      </connectionStrings>
Changed Connection String Add the Provider name:
<connectionStrings>
    <add connectionString="Server=servername;Database=dbname;User ID=userid;Password=password" name="MyConnectionstring" providerName="System.Data.SqlClient"
 />
      </connectionStrings>

Enjoy!!



Friday, August 26, 2011

SharePoint 2010:No Audience Targeting Option in SP2010 WebParts



Moving of webapplication from one server to another server, everything is working fine except "Target Audience". It is not displaying "Targeting Audience" as "WebPart" properties when edit the webpart.


So to make it enable and visible we do have a few workarounds.  Any one of workaround can fix this problem.

1> Make sure the User Profile Service Application is running and enabled under Service Connections for your target Web Application.  Go to Central Administration>Application Management>"Highlight Your Web Application">Service Connections>User Profile Service Applicatiton.  Ensure that you have a "Started" USPA  under Service Applications. 

2> Activate publishing feature on your site collection.

3> Go to Site Setting √†Site Collection Administration √† Site Collection Navigation Settings and Make sure audience targeting is checked.


















4> Do a simple "iisreset /noforce" can fix this.

Enjoy!!!!

Thursday, August 25, 2011

Hide the Quick Launch in SharePoint 2007/2010

We do have one requirement in which customized search result page  needs to use full width of the page , it means I need to hide Quick Launch for that page.

There is not any out of the box way by which we can easily hide or make invisible the Quick Launch and the Tree View navigation in SharePoint 2010 sites. 

How to do this?

The easiest way is to do this is
1> Edit the Page by selecting from Site Actions.
2> Add a Content Editor Webpart
3> Add the following text in the HTML Source mode:

#s4-leftpanel{
display:none
}
.s4-ca{
margin-left:0px
}

I applied this logic to pages which are related to Team Site.

See the magic!!!!! :)

Disha Shah

Wednesday, August 24, 2011

SharePoint 2010 :JQuery Magic SPCascadeDropdowns with the same list

Hello Friends


I have this below situation in which all SharePoint lists has been created  and deployed to the production and Users are using this list , their list structure is like this.


First List ,name is "Country" list  which contains "title" field is text field and act as "Country" and "State" field contains name of the State in that country.


Below  is the "City" list in which  we have Country and State as Lookup column and "Lookup" list is "Country" and City name will come under the "Title" field.


Now, on production actual problem has been started when they insert the city inside the list,  because country and state has not been cascading. It is production and people already using it. How to add atleast the minimum cascading so user select the right state depends on country.

Let us use the magic of JQuery.

Here is simple javascript code that I have used to accomplish this.

<script language="javascript" src="/Shared%20Documents/jquery-1.3.2.min.js" type="text/javascript"></script><script language="javascript" src="/Shared%20Documents/jquery.SPServices-0.6.2.min.js" type="text/javascript"></script><script language="javascript" type="text/javascript">

var sCamlQuery = "";
$(document).ready(function() {

// Cascade definition for State dropdown
$().SPServices.SPCascadeDropdowns({
    relationshipList: "Country",
    relationshipListParentColumn: "Title",
    relationshipListChildColumn: "State",
    parentColumn: "Country",
    childColumn: "State" ,
    completefunc: function() {
        sCamlQuery = "<Eq><FieldRef Name='Title'/><Value Type='Text'>" + $("select[title='Country'] option:selected").text() + "</Value></Eq>";
    }
  });
});</script>

After add this script inside the "Content Ediotr Webpart" we have below results, users happy , we happy.























Exact thing what we need!!!
Thanks JQuery!!!

Disha Shah

Tuesday, August 9, 2011

SharePoint 2010: Change the “Add New Item” (and other) messages for a all SharePoint List Types

In SharePoint, to add a new item/document we always have one standard message like “Add a new item”.

Users who are familiar with SharePoint they are used to understand but sometimes users do not understand they have question why I it always has said “ Add a new item”. So to avoid confusion let us add user friendly message.

How to do that? Let us use power of javascript.

Steps:

1. Add a content editor webpart in the page and add this javascript. Add Content Editor Webpart at the end of the page after list.

2. “<script> document.getElementById("idHomePageNewItem").innerHTML="Click here to insert a new country"</script>
This is just the text message for SharePoint Custom List how to make change for each type of list.

Below is list for id for every SharePoint list type.

ID’s used by web parts
SharePoint List Type
Default message
ID for “.getElementById” in the code below
Announcements
Add new announcement
“idHomePageNewAnnouncement” (changed in 2010)
Links
Add new link
"idHomePageNewLink" 
Calendar
Add new event
"idHomePageNewEvent"
Picture Library
Add new picture
“idHomePageNewItem”  *  (changed in 2010)
KPI List
Add new item
"idHomePageNewItem"  *  (changed in 2010)
Tasks
Add new item
"idHomePageNewItem"  *  (changed in 2010)
Project Tasks
Add new item
"idHomePageNewItem"  *  (changed in 2010)
Document Library
Add new document
"idHomePageNewDocument" 
Wiki
Add new Wiki page
"idHomePageNewWikiPage"  
Discussion
Add new discussion
"idHomePageNewDiscussion" 
Custom List
Add new item
“idHomePageNewItem”

Hope this helps!!!
Disha Shah

Monday, August 8, 2011

Read only field in SharePoint EditForm.aspx via Javascript


When we need to make some fields as read only when users wants to edit the item.This thing we can do very easily by SharePoint Designer , open that edit form and create one custom form and edit the field in which we want to make as read only we can change displaymode as edit. But what if do not want to change by SharePoint Designer.
We have very easy way which named as “JavaScript”.
I need to make one field as read-only, here is sample code
Open the editform.aspx page for a list and add one “Content Editor Webpart”, add the below javascript code.
<script type="text/javascript">

function MakeReadOnly()
{
// find all the elements with tag Name as INPUT
var elements=document.body.getElementsByTagName("INPUT");
// loop through all the elements till we find an element with type text and title as name of our field
for (index=0; index < elements.length;++index)
{
if(elements[index].type=="text")
{
if(elements[index].title=="Address") //Field name
{
elements[index].readOnly=true;
}
}
}
}
_spBodyOnLoadFunctionNames.push("MakeReadOnly()");</script>

Hope this helps!!!
Disha Shah

Monday, August 1, 2011

SharePoint : Validate controls before the item is saved via PreSaveAction() in SharePoint 2007/2010

I do have one requirement in which I need to check if they check one of the checkbox then they must have to enter the value. Without eventhandler or any custom code how could we do that?
We can achieve this thing via Content Editor WebPart and write JavaScript inside that. PreSaveAction() is manly used to validate controls before the item is saved( new item or edit).
How to do that?
Let us edit the page and add one content editor webpart , and add the javascript code in that content editor webpart and save page.
Sample of Javascript Code.
<script type="text/javascript">
function PreSaveAction()
{
var control = getTagFromIdentifierAndTitle("input","BooleanField","Other available");
var control1 = getTagFromIdentifierAndTitle("input","TextField","Other Value");
if(control.checked)
{
var StrToCheck= control1.value.replace(/^\s+|\s+$/, '');
//then we check for the length of the string if its 0 or not
if( StrToCheck.length==0 || StrToCheck =='0')
{
alert('Enter the value for Other');
}
}
else
{
control1.value=0;
}
return false;
}
function getTagFromIdentifierAndTitle(tagName, identifier, title) {
  var len = identifier.length;
  var tags = document.getElementsByTagName(tagName);
  for (var i=0; i < tags.length; i++) {
    var tempString = tags[i].id;
    if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
      return tags[i];
    }
  }
  return null;
}</script>

Hope this helps!!!
Disha Shah

Monday, July 25, 2011

SharePoint 2010 Membership Error :“The method or operation is not implemented”

Hello Friends
I was working with “Claims based authentication” in SharePoint 2010, develop registration page for new user so first I need to check whether that user already exists or not so when I checked for GetUser of Membership it always  throws error
I got this error: “The method or operation is not implemented”.
Nothing about my membership provider was custom, it was all default .Net stuff. I also found this to happen on other methods provided by the Membership object.
We can find out from here
MembershipProvider _provider = Membership.Providers["MyCustomMembershipProvider"];
MembershipUser user = _provider.GetUser(“username”, true);

if (user == null)
{
}
 ["MyCustomMembershipProvider "] is provider name in web config file

Hope this helps!!!
Disha Shah

Thursday, July 21, 2011

Error occurred in deployment step 'Retract Solution': Attempted to perform an unauthorized operation.

I have created one Sharepoint 2010 WebApplication which uses classic based authentication and add myself as "Site Collection Administrator", then I need to convert Webapplication authentication type "classic based authentication" from "Claims Based Authentication". Then when that user tried to deploy solution it gives this error.

"Error occurred in deployment step 'Retract Solution': Attempted to perform an unauthorized operation."

How to solve this one?

1> In SharePoint 2010 go to Central Administration - Manage web applications (under Application    Management).

2> There you select the SharePoint application and press "User Policy" in the ribbon. Over there you add your user you want  deploy with and give him full control.
Disha Shah

Wednesday, July 20, 2011

How to Create a SharePoint Application Page for Anonymous Access

There are some occasions in which we need to give anonymous access to SharePoint Application Pages , but on that webapplication does not give  the anonymous access. Examples like Registration Page, Forgot Password page. So how to do that?
We need to do three things for that.
1. protected override bool AllowAnonymousAccess
        {
            get
            {
                return true;
            }
        }

2. Instead, you need to use another base class for your anonymous application page called UnsecuredLayoutsPageBase. MSDN reference at: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.unsecuredlayoutspagebase.aspx

3. Please make sure we don't use DynamicMasterPageFile="~/masterurl/default.master" your application layout pag .aspx file.
change it to MasterPageFile="~/_layouts/simple.master"

Friday, April 22, 2011

Active Directory Account Creation Mode In SharePoint 2010 Foundation

Hello Friends

In SharePoint 2010 Foundation, during configuration the last screen of the Config Wizard enables you to confirm the settings you have chosen before  committing to them. If you are doing anything other than a SharePoint Foundation install, you will see an Advanced Settings button that is grayed out. If you are doing a SharePoint Foundation install, this button is enabled. If you click the button, you are taken to the Enable Active Directory Account Creation Mode.

Active Directory Account Creation Mode (ADACM) :

It allows your SharePoint farm to be set up to automatically create Active Directory
users when you add them to SharePoint. These new accounts are created in the organizational unit (OU) specified on the screen. You can even have SharePoint e‑mail a notification to users when their
account is created, along with the password. This is a truly automated scenario that works very well
in hosted environments.IT is an interesting but mostly unused feature of SharePoint.

There is disadvantage too. So if you are deploying SharePoint in ADACM, you cannot
use your existing Active Directory accounts to access SharePoint. Users hate having one username and password; 

Remember, it is only available in Foundation, not Server.

Disha Shah

Wednesday, March 16, 2011

JQuery with a small example

Hello friends
I was just trying to use JQuery with SharePoint sites and here is the very basic example which toggles button.

Notes:  In JQuery, we can refer object with its ID by using #. ".toggle()" this function is already available inside the JQuery , so we just have to name it which saves time

Example:
$('#exapandButton').click(function()
{
$('#warning').toggle();
if ($('#warning').is(':visible'))
{
$(this).val('Hide');
}
else
{
$(this).val('Show');
}
}
);