Thursday, October 6, 2011

How to filter the data in data form web part using calender control


ParameterBinding Name="PFromDate" Location="Control(CalFrom,SelectedDate)" DefaultValue=""
ParameterBinding Name="PToDate" Location="Control(CalTo,SelectedDate)" DefaultValue=""


Convert the date into number (YYYYMMDD)

number(string(ddwrt:FormatDateTime(translate(string(ddwrt:FormatDate(string(@Report_x0020_Date),1033,1)),'/','-'),1060,'yyyyMMdd'))) >= number(string(ddwrt:FormatDateTime(translate(string(ddwrt:FormatDate(string($PFromDate),1033,1)),'/','-'),1060,'yyyyMMdd'))) and number(string(ddwrt:FormatDateTime(translate(string(ddwrt:FormatDate(string(@Report_x0020_Date),1033,1)),'/','-'),1060,'yyyyMMdd'))) <= number(string(ddwrt:FormatDateTime(translate(string(ddwrt:FormatDate(string($PToDate),1033,1)),'/','-'),1060,'yyyyMMdd')))

old: Wrong Calc
number(translate(string(ddwrt:FormatDate(string(@Report_x0020_Date), 1033, 1)),'/','')) >= number(translate(string(ddwrt:FormatDate(string($PFromDate), 1033, 1)),'/','')) and number(translate(string(ddwrt:FormatDate(string(@Report_x0020_Date), 1033, 1)),'/','')) <= number(translate(string(ddwrt:FormatDate(string($PToDate), 1033, 1)),'/',''))
new


Ref:


number(translate(string(ddwrt:FormatDate(string(@Report_x0020_Date), 1033, 1)),'/','')) = number(translate(string(ddwrt:FormatDate(string($PFromDate), 1033, 1)),'/',''))

ddwrt:FormatDate(string(@Report_x0020_Date), 1033, 1) >= ddwrt:FormatDate(string($PFromDate), 1033, 1) and ddwrt:FormatDate(string(@Report_x0020_Date), 1033, 1) <= ddwrt:FormatDate(string($PToDate), 1033, 1)


number(translate(string(ddwrt:FormatDate(string(@Report_x0020_Date), 1033, 1)),"/",""))

number(translate(string(ddwrt:FormatDate(string($PFromDate), 1033, 1)),'/',''))

Wednesday, October 5, 2011

How to disable the RichTextBox in SharePoint

function disableRichTextBox(ctrlComments)
{
ctrlComments.disabled=true;
ctrlComments.readOnly=true;
var elm = document.getElementById(ctrlComments.id + "_toolbar");
if (elm) {elm.disabled=true; elm.readOnly = true;elm.style.display = 'none';}
elm = document.getElementById(ctrlComments.id + "_iframe");
if (elm) {elm.disabled=true; elm.readOnly = true;elm.style.display = 'none';}
ctrlComments.style.display = 'block';
}

Wednesday, August 31, 2011

SharePoint 2010 Ribbon Customization

http://makarandrkulkarni.blogspot.com/2010/01/sharepoint-2010-ribbon-customization_23.html

Monday, August 1, 2011

New SharePoint 2010 content for download

http://www.wssdemo.com/Blog/archive/2009/10/19/new-sharepoint-2010-content-for-download.aspx

Friday, March 25, 2011

Hide List View Tool bar Items

function hideListViewToolbarItems()
{
var doc = document.getElementsByTagName('ie:menuitem');
for (var i = 0; i < doc.length; i++) {
var itm = doc[i];
if (itm.id.match('OpenInExplorer') != null)
{
var p = itm.parentNode;
p.removeChild(itm);
}

}
}

A few thoughts as to why it's not working...

1) Match for part of the text and leave off the "zz33_" as that part can be different for every page.

2) Don't delete the nodes, hide them

3) Make sure your code is loaded after the web part with the View dropdown (i.e. if using a Content Editor Web Part, move it under the list web part)

Reference:MSDN

Thursday, March 24, 2011

Add Web Parts to DispForm, EditForm or NewForm.aspx

One of the users of our SharePoint project asked if it was possible to show an “Item List” on the “View Item” page.

My first reaction was: “Of course it is, add a Web Part displaying the “Item List” to the page and we’re done”.

But when I browsed to the “View Item” page and clicked the “Site Actions” I noticed that there wasn’t an “Edit Page” option available. Strange, but after some -Googling- I found the following sollution:

  • Open IExplorer and navigate to your “View Item” page (DispForm.aspx)
  • Replace everything in the URL after “?ID=#“ with “&PageView=Shared&ToolPaneView=2″ (without the quotes of course) and press
After adding a Web Part to the page and saving it, the “Edit Page” option will be available the next time you click “Site Actions” on that Page.

Document library Views Dropdown to change the View disappeared

When you go to a document library or list in Sharepoint 2007, you see a dropdown in which you can select a different view or create a new view if you have the right permissions.

If you ever find yourself thinking “Where did the change the view dropdown go?”

Change view disappeared

Don’t worry, one of two things could have happened.

  1. You added a second document library webpart on your page, but this would be obvious because you would see two webparts, one with a dropdown and one without it.
  2. Your user (or yourself) -closed- the webpart and added it again, leaving the closed webpart on the page, but hidden. This one is harder to detect, because you only see the webpart without the dropdown.

Close webpart

How do you fix this?

In the first case there isn’t much of a problem, you -delete- the second webpart from the page or you leave it on there (but without the dropdown).

For the second case you’ll have to edit the page (Site Actions, Edit Page), press Add a Web Part. At the bottom of the dialog is a link “Advanced Web Part gallery and options“, click it. A side bar “Add Web Parts” appears. Below the “Select the collection you want to browse.” is a link called “Closed Web Parts“, when you click it the Web Part List with closed Web Parts appears. Select the Document Library Web Part and click the “Add” button on the bottom of the screen. The page will show the two Web Parts, -delete- the one without the dropdown and you’re back in business.

Why? A web part which shows a list is supposed to display only one view of the list at a time. But you can definitely change the view by modifying the shared web part properties.

Useful Parameters to date for WSS 3.0 and MOSS 2007

Back in the days of WSS v2 and SPS 2003, one could use some handy URL parameter passing to edit web pages and browse for or search web parts.

My three favorite parameters for WSS v2 and SPS2003 were:

To Correct or Remove Misbehaving Web Parts
http://server/default.aspx?Contents=1

To Open the Page in Web Part Design Mode
http://server/default.aspx?ToolPaneView=2

To Open the Search Web Part Zone
http://server/default.aspx?ToolPaneView=3

Now in WSS 3.0 and MOSS 2007 we have the much more practical approach of switching views. Enter the Site Actions Menu, using the menu options we can edit the page, browse to site settings, etc.. But what happens if the Site Actions menu is not visible on the page. Maybe it was missed in the look and feel or has been removed deliberately like I had to do recently for a client. Now why someone would need to remove it and how this can be achieved (in at least two ways) will be covered in a later post.

Here are my favorite parameters to date for WSS 3.0 and MOSS 2007:

To open the Design Bar - Useful for pages in the Pages Library
http://server/default.aspx?DisplayMode=Design

To turn on Web Part Zone Editing
http://server/default.aspx?ControlMode=Edit

Note: The Site Actions Menu is rights trimmed and that means not all users can see or use it. Users with limited access or read rights will not be able to make use of the URL\Query String parameters. The parameters are just an alternative to get to the editing\design controls rather then a security bypass.

Wednesday, February 23, 2011

how to do web part connections in SharePoint 2010

1) Add web part zones to that page
2) Add my custom web parts in that zones
3) Connect those web parts in the page itself.


When I created the web part using Visual Studio 2010 template, it got derived from System.Web.UI.WebControls.WebParts namespace,

I changed that to Microsoft.SharePoint.WebPartPages.WebPart which solved my problem.

Monday, January 31, 2011

Delete event receiver from a SharePoint list

  1. private void DeleteEventReceiverFromAList(string siteUrl)
  2. {
  3. using (SPSite site = new SPSite(siteUrl))
  4. {
  5. using(SPWeb web = site.OpenWeb())
  6. {
  7. try
  8. {
  9. SPList list = web.Lists["myList"];
  10. if (list != null)
  11. {
  12. string className = "EventReceiverClass";
  13. string asmName = "EventReceiverAssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a865f0ecc234ea51";
  14. web.AllowUnsafeUpdates = true;
  15. int receivers = list.EventReceivers.Count;
  16. bool isAddedReceiverExist = false;
  17. bool isUpdatedReceiverExist = false;
  18. for (int i = 0; i <>
  19. {
  20. SPEventReceiverDefinition eventReceiver = list.EventReceivers[i];
  21. if (eventReceiver.Class == className && eventReceiver.Type == SPEventReceiverType.ItemAdded)
  22. {
  23. eventReceiver.Delete();
  24. break;
  25. }
  26. }
  27. }
  28. }
  29. catch { }
  30. finally
  31. {
  32. web.AllowUnsafeUpdates = false;
  33. }
  34. }
  35. }
  36. }

Saturday, November 27, 2010

Response.Redirect with try, catch, and finally Blocks and using Statements

Response.Redirect with try, catch, and finally Blocks and using Statements

The finally block executes after calls to Response.Redirect in the try block. Response.Redirect ultimately generates a ThreadAbortException exception. When this exception is raised, the runtime executes all finally blocks before ending the thread. However, because the finally block can do an unbounded computation or cancel the ThreadAbortException, the thread will not necessarily end. Therefore, before any redirection or transfer of processing can occur, you must dispose the objects. If your code must redirect, implement it in a way similar to the following code example.

String str;
SPSite oSPSite = null;
SPWeb oSPWeb = null;

try
{
oSPSite = new SPSite("http://server");
oSPWeb = oSPSite.OpenWeb(..);

str = oSPWeb.Title;
if(bDoRedirection)
{
if (oSPWeb != null)
oSPWeb.Dispose();

if (oSPSite != null)
oSPSite.Dispose();

Response.Redirect("newpage.aspx");
}
}
catch(Exception e)
{
}
finally
{
if (oSPWeb != null)
oSPWeb.Dispose();

if (oSPSite != null)
oSPSite.Dispose();
}


Because a using statement instructs the run time to create a finally block,
whenever you use Response.Redirect within a using statement,
ensure that objects are disposed properly. The following code example shows how you can do this.

using (SPSite oSPSite = new SPSite("http://server"))
using (SPWeb oSPWeb = oSPSite.OpenWeb(..))
{
if (bDoRedirection)
Response.Redirect("newpage.aspx");
}


Thursday, November 25, 2010

How do I create shared assemblies



How do I create shared assemblies ?


How to install an assembly in the Global Assembly Cache in Visual Basic .NET or in Visual Basic 2005?

A shared assembly is one that is used by multiple applications on the machine. A shared assembly must have a name that is globally unique. The .NET Framework supports these naming requirements through a technique called strong names.

Shared assemblies must have a "strong name" consisting of the name of the assembly, the version, a 64 bit hash of a public key (called a ´token´) and the culture.

To create a strong name for an assembly (that is, to generate a public/private key pair), you'll have to use another utility called sn.exe.

In this article, we will create a Visual Basic 2005 component called myGAC. We will also create a key file named mykeys.key. We will sign our component with this key file and place it in

Global Assembly Cache

To create a Component we have to create a Class Library project by using Visual Studio .NET.

Step 1 : Open Visual Studio .NET


Create a new Class Library project named myGAC in Visual Studio .NET or in Visual Basic 2005.
Here is the code for the component. It just includes one method which returns a string.

imports system

namespace BuildGAC
public class HelloClass
public function GetData() as string
return ´hello, how are you doing!´
end function
end class
end namespace

Step 2 : Generating Cryptographic Key Pair using the tool SN.Exe


Now, we will use the SN tool to generate the cryptographic key pair, which is located in the \bin subdirectory, where the .NET Framework Solution Developer Kit (SDK) is installed. We will open the DOS prompt. The command-line statement format is:

sn -k "C:\[DirectoryToPlaceKey]\[KeyName].key"


Next, create a directory named mykeys in C:\ so that you can easily locate the key and access the key from the command prompt.

NOTE:

For most users, the .NET tools are located in C:\Program Files\Microsoft.NET\FrameworkSDK\Bin.

Type the following at the command prompt.

sn -k "C:\mykeys\mykeys.key"

Step 3 : Sign the component with the key


A key is generated, but it is not yet associated with the project's assembly. To establish the association, double-click the AssemblyInfo.vb file in the Visual Studio .NET or Visual Studio 2005 Solution Explorer. Add the following to the list of assembly attributes that are included in this file by default when a project is created in Visual Studio .NET or in Visual Studio 2005:


<Assembly: AssemblyKeyFile("C:\mykeys\mykeys.key")>


Now recompile the project and the assembly will be signed.

Below is a listing of the complete code of assembly AssemblyInfo.vb

Imports System.Reflection

Imports System.Runtime.InteropServices

<Assembly: AssemblyTitle("")>

<Assembly: AssemblyDescription("")>

<Assembly: AssemblyCompany("")>

<Assembly: AssemblyProduct("")>

<Assembly: AssemblyCopyright("")>

<Assembly: AssemblyTrademark("")>

<Assembly: CLSCompliant(True)>

<Assembly: AssemblyKeyFile("C:\mykeys\mykeys.key")>

<Assembly: Guid("E3492A62-5389-4286-94A3-1331CC29EA6D")>

<Assembly: AssemblyVersion("1.0.*")>


The next step is to install the assembly into the Global Assembly Cache.

Step 4 : Host the signed assembly in Global Assembly Cache


There are two ways to install an assembly into the global assembly cache:


Using Microsoft Windows Installer 2.0



This is the recommended and most common way to add assemblies to the global assembly cache. The installer provides reference counting of assemblies in the global assembly cache, plus other benefits.


Using the Global Assembly Cache tool (Gacutil.exe)


You can use Gacutil.exe to add strong-named assemblies to the global assembly cache and to view the contents of the global assembly cache.

Note:

Gacutil.exe is only for development purposes and should not be used to install production assemblies into the global assembly cache.

Syntax to install a strong-named assembly into the global assembly cache

You can install the .dll file by using the Gacutil Tool or by dragging the .dll file into the appropriate directory. If you use the Gacutil Tool, you can use the following command:

At the command prompt, type the following command:

gacutil ­I <assembly name>

In this command, assembly name is the name of the assembly to install in the global assembly cache.

The following example installs an assembly with the file name myGAC.dll into the global assembly cache.

gacutil -I "C:\[PathToBinDirectoryInVSProject]\myGAC.dll"

After hosting the assembly just go to WINNT\Assembly folder and you will find your assembly listed there.

Step 5 : Test the assembly


Once you've installed the assembly into the GAC, you can use it from other programs by creating a reference.

Now, we will create a sample client application which uses our shared assembly.

In our sample clientGACTest project, expand the project and then right-click on the References item. Select "Add Reference" from the popup menu, and the Add Reference dialog box is displayed.

To refer an assembly in the GAC, just click on the Browse button and browse to the directory (myGAC/bin/debug) that contains the assembly (myGAC.dll). Locate the assembly, select it, and click OK.

Click on the myGAC reference in Solution Explorer and then examine the Properties pane. You'll see that the Copy Local property is set to False, Strong Name is true, and that the assembly version is 1.0.2369.37199
Just create a sample code as listed below :
You can now compile and run the clientGAC program.
Imports System

Imports myGAC.BuildGAC

Public Class SampleTest

Shared Sub main()

Dim x As New HelloClass()

Dim s As String = x.GetData()

Console.WriteLine(s)

End Sub

End Class
Now, copy the resulting EXE in any other folder and run it. It will display "Hello World" indicating that it is using our shared assembly.

Summary:

This article describes how to generate a strong name for an assembly and to install a .dll file in the Global Assembly Cache. The Global Assembly Cache (GAC) enables you to share assemblies across numerous applications. The GAC is automatically installed with the .NET runtime. Components are stored in C:\WINNT\Assembly.


Disable the Anchor Tag Using JavaScript

function DisableTheAnchorTag()
{
var btnA= document.getElementById("name of the a tag");
if(btnA!= null)
{
btnA.onmouseover=function y(){this.style.cursor='default'}
btnA.setAttribute('onclick', "void(0);");
}
}

Tuesday, November 16, 2010

Get Current Logged On user using JavaScript

<script language="javascript" type="text/javascript">
_spBodyOnLoadFunctionNames.push("GetCurrentLoggedOnUserName");
function GetCurrentLoggedOnUserName()
{
var Loginname = document.getElementById("zz8_Menu").innerHTML ;
var end = Loginname.indexOf("<");
var nameOnly = Loginname.substring(8, end);
alert(nameOnly);
}
</script>

Jquery In SharePoint page

<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("GetAlert");

$(document).ready(function GetAlert() {
var thisUser = 'test';
alert(thisUser);
});

</script>

Monday, November 15, 2010

Getting Query parameters using Javascript

<script language='JavaScript'>
// get the current URL
var url = window.location.toString();
//get the parameters
url.match(/\?(.+)$/);
var params = RegExp.$1;
// split up the query string and store in an
// associative array
var params = params.split("&");
var queryStringList = {};

for(var i=0;i {
var tmp = params[i].split("=");
queryStringList[tmp[0]] = unescape(tmp[1]);
}

// print all querystring in key value pairs
for(var i in queryStringList)
document.write(i+" = "+queryStringList[i]+"<br/>");
</script>