Thursday, December 16, 2010

How to identify a SharePoint Site?

We have lot of websites in internet and many of them are in SharePoint. So if you see any good looking site on internet and you want to check whether it is sharepoint based site or not?

There are some really cool exceptional ways.

Take "View Source" from any browser of your site. You will see something like <head> <meta name = "Generator" content="Microsoft SharePoint"/>

Dont forget to check Javascript section just after <Title>

You will see reference JS from src="/_layouts/1033/init.js"

If its SharePoint site there are also webservice with it. You can call any of webservice (If banned you will see "Unknown Error" page). e.g http://SharePointSite.Microsoft.com/_layouts/Lists.asmx .

Otherway is check images folder available in 12 hive folder(e.g. http://SharepointSite.Microsoft.com/_layouts/images/accesssetting.gif), it will show you image available in 12 hive folder.
           

Monday, December 13, 2010

Session State Error in SharePoint 2010

ASP.NET session state may be used on SharePoint 2010 pages. This service is automatically disabled in normal installations of SharePoint 2010. To enable session State in SP 2010 follow beleow steps:-
    • Enter the following PowerShell command in the SharePoint 2010 Management Shell window:
      Enable-SPSessionStateService –DefaultProvision.
    • Steps for PowerShell:-
    • Go to all programs-->Microsoft SharePoint 2010 products-->SharePoint 2010 Managment Shell.
    • On each web application for which you want to use session state, edit the web.config file and set the enableSessionState property of the pages element as follows:
      <pages enableSessionState="true".

Friday, December 10, 2010

Session Error occur on SharePoint Site

Some times Session error occur on your sharepoint portal server when installing asp.net project/User Control on SharePoint Server. The user control handling some session value on that page.

To overcome the error used following steps:-
1.       Go to Central Admin à Application Management à Configure Session State à enabled session state.
2.       From a command prompt, navigate to the Microsoft.NET 2.0 Framework directory(C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG).
3.       Open web.config file and modified as follows:-
4.       Uncomment the line:- <add name=”Session” type=”System.Web.SessionState.SessionStateModule” />
5.       Modified the line:- <pages /> to <pages enableSessionState=”true” … />
6.       From a command prompt:- change c:\Documents and setting… to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
7.       Run the command:- aspnet_regsql.exe -S  <server_name>  -d <database_name>  -ssadd  -sstype c  -E
8.       Where server name = is the database server where your database is located (Mentioned in error page).
9.       Where database name = is the content database of your shared services provider(Mentioned in error page.
10.   Make IISReset.

Tuesday, October 26, 2010

Calculated columns cannot contain volatile functions like Today and Me

When you trying to add calculated formula in list based on current date. You add '[Today]' in your formula and you give error like:- "Calculated columns cannot contain volatile functions like Today and Me". See image below:-




To solve this error use following steps:-

  1. Open up the List Settings page where you want this column.
  2. Create column named “Today”. The type doesn’t matter here, so let type as “Single Line of Text” and just click “Ok” 










3. Now create the calculated column where you need to use current date within formula and add “Today” from available columns.


















4.Once this is done, we no longer need that our own generated column “Today” so you can delete it (Although when you need to edit formula you will need this again, so either recreate this dummy Today field or make it hidden using code behind. Otherwise SharePoint will put you again on that error screen).






5.For calculated fields, calculated value is stored in Database when item is created at first time and doesn’t change until item is edited. So using Today doesn’t means each time you will get value re-calculated as per actual today’s date. For that it is better to use Computed column.

Thursday, October 21, 2010

"Errors were found when compiling the workflow.The workflow files were saved but cannot be run."

When you create workflow using sharepoint designer tool and you get the following error:-

 "Errors were found when compiling the workflow.The workflow files were saved but cannot be run." and if you click on details button you get message "Unexpected error on server associating the workflow".

The problem with your web.config file. If you install some third party workflow tool(e.g Nintext,Sogeti,EdinKapic) and unistall it, referrence dll not removed from your web.config file. 

To remove error use following steps:-
  1. Open your web.config file in Visual studio.
  2. Go to "<System.Workflow.ComponentModel.WorkflowCompiler>"
  3. The third party workflow tool reference available here. e.g. Sogeti.Workflow tool
  4. <authorizedType Assembly="Sogeti.Workflow.Activities,Version=1.0.0.0, Culture=neutral, PublicKeyToken=1cdaea2144644b9c" Namespace="Sogeti.Workflow" TypeName="*" Authorized="True" />
  5. Comment the third party tool reference, you uninstall previously.
  6. Save web.config file and reset server.
  7. Now your workflow run normally.

Saturday, October 16, 2010

Difference between SPWeb.Users, SPWeb.AllUsers, SPWeb.SiteUsers

SiteUsers,  AllUsers and  Users are properties of SPWeb Object. But looking to this properties name,  its not easy to understand their’s scope.  So below is description about this properties:-



  1. SPWeb.Users :- This represents the collection of users or user objects who have been explicitly assigned permissions in the Web site . This does not return users who have access through a group.
  2. SPWeb.AllUsers :-This gives us the collection of user objects who are either members of the site collection or who have atleast navigated to the site as authenticated members of a domain group in the site.
  3. SPWeb.SiteUsers :- This is the collection of all users that belong to the site collection.

Tuesday, September 28, 2010

Remove user acess from sharepoint site.

If some user is no longer with company and you want that user not get permission to access SharePoint site and mail go to that particular user.

If you remove the particular user from AD or disable the account in AD, the mail account also disable and the user not get mail.

For remove the particular user use following steps:-

1) Go to Central Administration àApplication Management àPolicy for Web Application

2) Click on Add Users. Select Web Application for which you want to disable access.

3) Select Zones as (All Zones) and click on next button.

4) Add user in Choose user section and select “Deny All – Has no access ”.

5) Click on Finish.

6) The particular user not gets access to the particular site collection.

Thursday, September 23, 2010

Hide/Remove Title Column from List

Many times i thought that there must be a way to get rid of this Title column, because it's name does not suit the business requirements most of the time.


Better way to hide that column from list. Follow the steps mentioned below:-


1)Go to Your list settings on which you want to hide/remove title column.
2)Go to advanced settings of that list.
3)Click on yes at Allow management of content types.
4)Once you do this, one more setting panel becomes visible in advanced settings options. check out the figure below.

5) Now click on Item content type.
6)Click on Title under section Columns.
7)Select radio button "Hidden (Will not appear in forms)".
8)Click on OK button.
9)The column hide from Add.aspx and Edit.aspx page.
9)Go to AllItem.aspx page and hide column in view also.

Remove link on Lookup Field in List

When we add lookup column to any list item add item, the link appears on lookup column. If you check the link, link something like "http://Site/ListName/DispForm.aspx?ID=ID of that field>>&RootFolder=*". 


we find all the Anchor element of the document and check index of href attributes "&RootFolder=*". If you get this attributes simple remove link of lookup.


Add "Content Editor Web Part" webpart on AddItem.aspx page of list. Add the following javascript in webpart:-


<script language="javascript" type="text/javascript">

_spBodyOnLoadFunctionNames.push("RemoveLookupLinks");
function RemoveLookupLinks()
{
var oP = document.getElementsByTagName('a');//the collection of <a> tags
var flag = false
for(var i=0;i<oP.length;i++)
{
if(oP[i].attributes["href"].value.indexOf("RootFolder=*")!= -1)
{
var linkvalue = oP[i].innerHTML;//value of the lookup field
oP[i].parentNode.innerHTML = linkvalue;//replacing value of the lookup to whole the Anchor tag
flag = true;
break;
}
}
if(flag)
RemoveLookupLinks();
}
</script>






Turn Off Send mail option when user add to group.

When we add user to group there is an option "Send E-Mail" and the check box by default selected. Many times
 on client machine when we add the user to group mail fired to user due to this functionality.

If you want to turn off  "Send Mail" option go through following steps:-

1)Open Program Files -> Common Files -> Microsoft Shared -> Web server
extensions -> 12 -> Template -> Layouts  

2)Open AclInv.aspx


3) Find 
<wssawc:InputFormCheckBox
 runat="server"
id="chkSendEmail"
Checked="True"
LabelText="<%$Resources:wss,aclver_SendEmailCheckbox%>"
ToggleChildren=true>


4) By default Checked property is "True". Make it to "False" and save the page.


5) When you add user to group the "Send E-Mail" check box now turn off.


Happy Coding....................

How to develop Custom Tool Part?

What is Tool Part?

When we modified webpart present on SharePoint page, at the time what appears on right hand side is panel. We can specify webpart properties there.
If you want to add custom property to that tool part panel, your webpart should be inherits with “Microsoft.SharePoint.WebpartPages.webpart” instead of “System.Web.UI.WebControls.Webparts.Webpart”.

Let us see example:-
You want to add “Customer name” textbox to tool pane.
Step 1: -
Declare variable for “Customer name” property and add the code within your webpart class.
private string strCustomerName = string.Empty;

[Browsable(false),//Display the property in property pane
Category("CustomToolPart"),//Create a Customer Details category in property pane
DefaultValue(""),//Assign a default value
WebPartStorage(Storage.Personal),//Make available in both personal and shared mode
Personalizable(PersonalizationScope.User),
FriendlyName("Customer Name"),//The caption display in property pane
Description("The name of the customer")]//The tool tip

public string CustomerName
{

get
{
return strCustomerName;
}
set
{
strCustomerName = value;
}
}
If you want to add more properties, you can declare in your webpart class.
Now override one method  which is GetToolParts() on ToolPart method.
public override ToolPart[] GetToolParts()
{
ToolPart[] toolparts = new ToolPart[3];

WebPartToolPart wptp = new WebPartToolPart();

CustomPropertyToolPart custom = new CustomPropertyToolPart();

toolparts[0] = wptp;

toolparts[1] = custom;

toolparts[2] = new {toolpartclass}

return toolparts;
}

In above code “WebPartToolPart” having default properties available in sharepoint and “CustomPropertyToolPart” having customproperty that you want to added.

Ok, let’s develop and create Tool Part class which will have RenderToolPart and ApplyChanges method.

Create a class which inherits from Microsoft.Sharepoint.WebpartPages.ToolPart.

Declare variable which will be name of control render in tool pane.

private string strHTMLinputControlName = "Mycontrol";

protected override void RenderToolPart(HtmlTextWriter output)

{

// Establish a reference to the Web Part.

// CustomWebPart is the web part class name.

{webpartclassname} customWebPart =

(webpartclassname)this.ParentToolPane.SelectedWebPart; 

//Create the input control

output.Write("Enter the customer name: ");

output.Write("<input name= '" + strHTMLinputControlName); 

output.Write("' type='text' value='" + 

SPEncode.HtmlEncode(customWebPart.CustomerName) + "'><br>"); 

}

We have first taken the reference of the webpart class for which we are creating this tool part. So parentToolPane.SelectedWebPart will be the webpart for which we are creating tool Part. Add the following method.

public override void ApplyChanges()
{

// apply property values here

//Get a reference to the web part class

{webpartclassname} cw1 =

(webpartclassname)this.ParentToolPane.SelectedWebPart;

//Pass the custom text to web part custom property

cw1.CustomerName = Page.Request.Form[strHTMLinputControlName];

}

The “ApplyChanges” method which will be called when we press OK. The webpart is now completed with your custom tool pane property. 

Deploy the webpart to your site and add webpart on sharepoint page.
When you edit webpart properties, in tool pane you will find property you have added previously.

Happy coding………………..




Monday, August 16, 2010

Redirect AddForm.aspx,EditForm.aspx Page to custom page.

Bydefault SharePoint List AddForm.aspx and EditForm.aspx page redirect you to AllItem.aspx page when you click on "OK" or "Cancel" button.

If you want to redirect your AddForm.aspx and EditForm.aspx page to your custom page, here is the solution.

1) Open your AddForm.aspx page in SharePoint Designer.
2) Right click on SharePoint ListForm Webpart, go to webpart properties and hide webpart.
3) Add Custom List Form from Insert->SharePoint Control.
4)Select your list name and select your form (e.g New Item Form).
5)Comment save button().
6)Insert javascript with button like (<button id="savebutton1" name="Ok" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={/Subsite/Pages/test.aspx}')}" style="width: 16px;" title="Ok" value="Ok"></button>)
 Or

<input name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent('__redirect={/subsite/Pages/test.aspx}')}" type="button" />
7)Save the page and check page is now redirect to your sprecified link.

Saturday, August 14, 2010

SharePoint Exception: No item exists [url]. It may have been deleted or renamed by another user.

This is one of the exception regularly comes when we do custom development and create custom aspx pages. Everything works fine and no code issues but still this exception comes.


Error occur as :- No item exists at http://sitename/pagename.aspx?Id=2.It may have been deleted or renamed by another user.


The issue can be easily solved by renaming the querystring parameter to a different name other than Id
(E.g http://sitename/pagename.aspx?empid=2).


After renaming the parameter the Sharepoint page will work as expected.


The issue occurs due to conflict of querystring parameter Id with sharepoint list Id.


Hope this helps and save you from killing so much time to know the problem.









Friday, August 13, 2010

Recover broken sharepoint list forms NewForm.aspx,EditForm.aspx.

If you've ever played around with any of the SharePoint list forms (NewForm.aspx, EditForm.aspx) in SharePoint Designer, then you may (probably) have been faced with broken links and a host of other errors that have rendered your forms, and quite probably your list, useless.

I faced similar problem in last month. I was spend around 1 day to re-correct that page, but no output. Luckily there's an easy way to fix this, its take hardly 5 min.


Here are the things you'll need to fix your forms:

  1. With the broken form page already open in SharePoint Designer, open any form that is NOT broken. This can be any form from from any list as long as it works.
  2. Remove ListFormWebpart from broken page  "<WebPartPages:ListFormWebPart ... to</WebPartPages:ListFormWebPart>"
  3. Copy ListFormWebPart from unbroken list page open in previous and paste it into the broken form.
  4. Paste the List GUID in &ltListName ... between the { and }.
  5. Generate a form GUID from Visual Studio or click on http://www.somacon.com/p113.php to generate GUID and paste it into the ... __WebPartID="{[Form GUID]}" > and the <ID>g_[Form GUID]</ID>.
  6. Save the page and refresh the list in your browser. The page should now be fixed.