Wednesday, 28 December 2011

Cascading Drop Down SharePoint 2010

our new blog site : http://blog.hintechnology.com
Cascading Drop Down
The request for Cascading Drop Down, filtered drop down, dependent drop down or what you call them is one of the most common requirements from customers. This rather basic functionality is surprisingly not implemented in either WSS 3.0 or MOSS 2007.
What is Cascading Drop Down?
You have two columns in your SharePoint list, Country and City. Both are lookup/drop down columns. When you choose a country in the Country Drop Down, you only want to see the cities in this country available in the City Drop Down column. This of course makes life easier for the end user, and improves data quality.
The solution
Instead, I have used this solution with success. The list is still standard SharePoint, which gives great flexibility and stability. This way, the filtering is done in the forms for creating and editing elements. Because of this, you don’t even have access to the server to implement this. I have used this solution both in document libraries and in regular SharePoint lists.
1. Add the Jacascript
Download the Jquery file  http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js  by Jquery.com. Download jquery.SPServices-0.4.8.zip from the Jquery Library for SharePoint Codeplex site (newer version is probably also OK). Upload http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js and jquery.SPServices-0.4.8.min.js (from the zip file) to a document library that everyone accessing your site has access to (a library on the top level site can be wise).
2. Create your relationship lists
Make two lists, one for the parent (Country) and one for the child (City):



The Country column can be a look up from the Countries list, but you can just as well use a standard single line of text column. This can theoretically give better performance, but you must of course be precise when filling out the County column so that the values here matches the ones in the Countries list.
3. Create the list using the Drop Down

Vacation Plan List






Vacation Plans list:


This is the list where I want my Cascading Drop Downs. Country and City are lookup columns against Countries and Cities lists. The lookups goes against the title field in the respective columns.
4. Make the magic happen
In SharePoint Designer, create your own NewForm.aspx (or EditForm.aspx, you’ll need both if you want it to work when editing items).If you don’t know how to do this, I’ll probably post a tutorial later. Tip: don’t edit the existing forms, but copy them and assign them as default forms.
Just below
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
insert this code:
NOTE: For this you have to move into Advanced Mode of the page in Page code view side.
<script language="javascript" type="text/javascript" src="/address to document library/jquery-1.3.2.min.js"></script>
<script language="javascript" type="text/javascript" src="/address to document library/jquery.SPServices-0.4.8.min.js"></script>
<script language="javascript" type="text/javascript">
 $(document).ready(function() {
  $().SPServices.SPCascadeDropdowns({
   relationshipList: "Cities",
   relationshipListParentColumn: "Country",
   relationshipListChildColumn: "Title",
   parentColumn: "Country",
   childColumn: "City",
   debug: true
  });

 });
</script>

Save and create a new item using your new form:

Ajax Control Toolkit with SharePoint 2010

our new blog site : http://blog.hintechnology.com

Ajax Control Toolkit with SharePoint 2010

I had to use Ajax control toolkit with sharepoint and I had download the latest version from codeplex. We usually download latest versions of software because we believe that with latest version we can get more features and more bug-free. I had used Ajax Control Toolkit with SharePoint 2007 and it was much easier to configure and use Ajax Control Toolkit. With that belief in mind I had started using Ajax Control Toolkit in SharePoint 2010 downloading latest version for .net framework 3.5. But I failed  and after investigating I had found the following errors.
  • AjaxControlToolkit requires ASP.NET Ajax 4.0 scripts. Ensure the correct version of the scripts are referenced. If you are using an ASP.NET ScriptManager, switch to the ToolkitScriptManager in AjaxControlToolkit.dll.
  • Sys.registerComponent is not a function

The problem here is that latest versions of Ajax Control Toolkit is more optimized or targeted with .net framework 4.0. Even the Ajax control toolkit for .net framework 3.5 doesn’t work with SharePoint 2010. If you try to use Ajax Control Toolkit for 3.5 with SharePoint 2010, you may get the exceptions shown above.

How to make Ajax Control Toolkit working with SharePoint 2010?
Here are the steps to make Ajax Control Toolkit working with SharePoint 2010.
  1. Download Correct (compatible) version of Ajax Control Toolkit.
Since current release of Ajax Control Toolkit doesn’t work with SharePoint 2010, you need to download previous release. Maybe Ajax Control Toolkit team will address this issue and we’ll be able to use current Toolkit version with SharePoint in future. Until the current release is made compatible, please download the SharePoint 2010 compatible Ajax Control Toolkit from here.
  1. Add AjaxControlToolkit.dll reference to your project
To use the Ajax Control Toolkit in your SharePoint project, add reference to the AjaxControlToolkit.dll in your project. To use the Ajax Control Toolkit in any web part control add the following lines to register the Ajax Control Toolkit namespace.
<%@ Register Assembly="AjaxControlToolkit, Version=3.0.30930.28736,
 Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"

Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
  1. Remember, here version 3.x version of Ajax Control Toolkit is used instead 3.5.
  2. Add Ajax Control Toolkit ScriptManager in master page.
Open the Master page in SharePoint Designer. By default the v4.Master file is the default master page can be found “_catalogs/masterpage” folder. Before modifying the master page, keep a backup copy.
    • First register the Ajax Control Toolkit namespace in the masterpage file by putting the following line at the top of the file:
<!--[if !supportLists]-->o    <!--[endif]--><%@ Register Assembly="AjaxControlToolkit, Version=3.0.30930.28736,
 Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"

Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
    • Then remove the ScriptManager registration from the master page by removing the following line:
<!--[if !supportLists]-->o    <!--[endif]--><asp:ScriptManager id="ScriptManager" runat="server" EnablePageMethods="false" 
EnablePartialRendering="true" EnableScriptGlobalization="false" EnableScriptLocalization="true"/>
    • Finally Add the following line in place of the above line to register Ajax Control Toolkit
<!--[if !supportLists]-->o    <!--[endif]--><ajaxToolkit:ToolkitScriptManager id="ScriptManager" runat="server" EnablePageMethods="false"
EnablePartialRendering="true" EnableScriptGlobalization="false" EnableScriptLocalization="true"/>
  1. Register Ajax Control Toolkit namespaces in SharePoint package Designer 
Finally, you need to register the Ajax Control Toolkit namespace with SharePoint Package designer. Registering Ajax Control Toolkit namespaces will add Ajax Control Toolkit namespaces in web.config’s safecontrol list. First open the Package designer in Visual Studio (Package usually exists under Package folder in Visual Studio). And then click the “Advanced” button in package designer window as shown in the image below. In that advanced tab you can add/edit assemblies to be registered safe as part of the deployment of the solution package. Click Add ==> “Add Existing Assembly”. The following image shows wizard to follow.



Figure 1: Above Package Designer’s Advance tab
In the “Add existing Assembly” window, add the following namespaces for Ajax Control Toolkit.
Namespace
Type Name
Assembly Name
AjaxControlToolkit
*
AjaxControlToolkit
AjaxControlToolkit.Design
*
AjaxControlToolkit
AjaxControlToolkit.HTMLEditor
*
AjaxControlToolkit
AjaxControlToolkit.HTMLEditor.Popups
*
AjaxControlToolkit
AjaxControlToolkit.HTMLEditor.ToolbarButton
*
AjaxControlToolkit
AjaxControlToolkit.MaskedEditValidatorCompatibility
*
AjaxControlToolkit
The following image shows the “Add Existing Assembly” window for AjaxControlToolkit dll.




Figure 2: Add/Edit Existing Assembly window
Now you can build and deploy the package and as a result of deployment, Ajax Control Toolkit namespaces will be registered as safe controls in web.config.
Conclusion
Its really hard to believe that Ajax Control Toolkit’s  latest version doesn’t work with SharePoint. We expect to have the latest version of Ajax Control Toolkit to be compatible with SharePoint 2010. Until then we might have to use an old version of Ajax Control Toolkit.

For More Details you can visit : 
http://ranaictiu-technicalblog.blogspot.com/2010/08/ajax-control-toolkit-with-sharepoint.html




Step By Step InfoPath form using Web Service in SharePoint 2010

our new blog site : http://blog.hintechnology.com

Step By Step Creating Web Service InfoPath Form 2007 in SharePoint  2010
1.       Create Web Service Using Visual Studio 2008, 2010.


      Host the Web Service in the IIS Server.



Open the InfoPath 2007 and Select the Web Service from the Example of Design Form.



 Then configure the web service path and Other url details and sharepoint details in the dialog 






























2.       


3.     

4

Monday, 26 December 2011

Week days between two dates

our new blog site : http://blog.hintechnology.com
public static int  WeekCount(DateTime startDate, DateTime endDate, DayOfWeek Week)
{
    // Number of days between start date and end date
int _noOfDays = (endDate - startDate).Days;      
   // days between week of start date
    int _adjustingDays = (7 + (int)Week - (int)startDate.DayOfWeek) % 7
// days remain after total days after dividing 7
int _remainDays = _noOfDays % 7; int _totalWeekTurns = (_noOfDays) / 7; int _addTurns = _remainDays >= _remainDays ? 1 : 0;   return _totalWeekTurns + _addTurns; }

Thursday, 15 December 2011

Creating Custom Level Menu in SharePoint 2010, MOSS 2007

our new blog site : http://blog.hintechnology.com
Creating Custom 3 Level Menu IN SharePoint
1. Creating a SharePoint list that will manage you navigation.
2. Create you wep part code for the menu.
3. Add your Menu web part in your master page.
4. Test your application to view the result.

1. Create a SharePoint List Which look like this having the following field in it;




Item level column to have choice field type and three level Level 1, Level 2, Level 3,


Display0 column will also have the choice field with yes and no value




2 And after you have created the menu list now you can create your own Menu web part

Here is the code which for the menu web part;

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Drawing;

namespace MenuWebPart
{
    [Guid("743ab9a9-31e0-4ba4-b2bc-cbb5696bd18e")]
    public class Menu : System.Web.UI.WebControls.WebParts.WebPart
    {
        public string _AdminList = "[type_list_Name_of_Menu/ CustomMenu]";
        public Menu()
        {
            this.ExportMode = WebPartExportMode.All;
        }

        [Personalizable, WebBrowsable, WebDisplayName("Admin List")]
        public string Set_AdminList
        {
            get
            {
                return _AdminList;
            }
            set
            {
                _AdminList = value;
            }
        }

        protected override void CreateChildControls()
        {
            // Create ASPMenu control.
            AspMenu _menu;
            string MenuID = _AdminList + "CustomMenu";
            _menu = new AspMenu();

            //Set the controls look and feel
            _menu.ID = "CustomMenu";
            _menu.EnableViewState = false;
            _menu.Orientation = System.Web.UI.WebControls.Orientation.Horizontal;
            _menu.StaticDisplayLevels = 1;
            _menu.MaximumDynamicDisplayLevels = 3;
            _menu.StaticSubMenuIndent = 0;
            _menu.DynamicHorizontalOffset = 0;
            _menu.StaticPopOutImageUrl = "/_layouts/images/arrow.png";
            _menu.StaticPopOutImageTextFormatString = "";
            _menu.DynamicHoverStyle.BackColor = Color.FromName("#CBE3F0");
            _menu.SkipLinkText = "";
            _menu.StaticSubMenuIndent = 0;
            _menu.CssClass = "ms-topNavContainer";

            _menu.StaticMenuItemStyle.CssClass = "ms-topnav";
            _menu.StaticMenuItemStyle.ItemSpacing = 0;
            _menu.StaticSelectedStyle.CssClass = "ms-topnavselected";
            _menu.StaticHoverStyle.CssClass = "ms-topNavHover";
            _menu.DynamicMenuStyle.BackColor = Color.FromName("#F2F3F4");
            _menu.DynamicMenuStyle.BorderColor = Color.FromName("#A7B4CE");
            _menu.DynamicMenuStyle.BorderWidth = 0;
            _menu.DynamicHoverStyle.BackColor = Color.FromName("#525252");
            _menu.DynamicHoverStyle.BorderColor = Color.FromName("#CBE3F0");
            _menu.DynamicMenuItemStyle.CssClass = "ms-topNavFlyOuts";
            _menu.DynamicHoverStyle.CssClass = "ms-topNavFlyOutsHover";
            _menu.DynamicSelectedStyle.CssClass = "ms-topNavFlyOutsSelected";

            SPWeb thisWeb = null;

            try
            {

                SPSite thisSite = SPControl.GetContextSite(Context);
                thisWeb = thisSite.OpenWeb();
                SPList spCascadingNav = thisWeb.Lists[_AdminList];

                SPQuery query = new SPQuery();
                //query.Query = "<OrderBy><FieldRef Name='Link_x0020_Order' /></OrderBy><Where><And><Eq><FieldRef Name='Item_x0020_Level' /><Value Type='Choice'>Level 1</Value></Eq><Eq><FieldRef Name='Display' /><Value Type='Choice'>Yes</Value></Eq></And></Where>";
                query.Query = "<OrderBy><FieldRef Name='Link_x0020_Order' /></OrderBy><Where><And><Eq><FieldRef Name='Item_x0020_Level' /><Value Type='Choice'>Level 1</Value></Eq><Eq><FieldRef Name='Display0' /><Value Type='Choice'>Yes</Value></Eq></And></Where>";
                SPListItemCollection items = spCascadingNav.GetItems(query);

                //For each item, generate the row.
                System.Web.UI.WebControls.MenuItem _item = new System.Web.UI.WebControls.MenuItem();
                System.Web.UI.WebControls.MenuItem _item2;
                System.Web.UI.WebControls.MenuItem _item3;

                foreach (SPListItem menuItem in items)
                {
                    string parentID = " ";
                    if (menuItem["Parent ID"] != null)
                    {
                        parentID = menuItem["Parent ID"].ToString();
                    }
                    else { parentID = "None"; }
                    string title = menuItem["Title"].ToString();
                    string url = menuItem["Link URL"].ToString();
                    string itemID = menuItem["Link ID"].ToString();

                    _item = new System.Web.UI.WebControls.MenuItem(title, "", "", url);

                    SPQuery level2query = new SPQuery();
                    level2query.Query = "<OrderBy><FieldRef Name='Link_x0020_Order' /></OrderBy><Where><And><Eq><FieldRef Name='Item_x0020_Level' /><Value Type='Choice'>Level 2</Value></Eq><Eq><FieldRef Name='Display0' /><Value Type='Choice'>Yes</Value></Eq></And></Where>";
                    //level2query.Query = "<OrderBy><FieldRef Name='Link_x0020_Order' /></OrderBy><Where><And><Eq><FieldRef Name='Item_x0020_Level' /><Value Type='Choice'>Level 2</Value></Eq><Eq><FieldRef Name='Display' /><Value Type='Choice'>Yes</Value></Eq></And></Where>";
                    SPListItemCollection level2items = spCascadingNav.GetItems(level2query);

                    foreach (SPListItem subMenuItem in level2items)
                    {
                        string subparentID = " ";
                        if (subMenuItem["Parent ID"] != null)
                        {
                            subparentID = subMenuItem["Parent ID"].ToString();
                        }
                        else { subparentID = "None"; }

                        if (subparentID == itemID)
                        {
                            string subtitle = subMenuItem["Title"].ToString();
                            string suburl = subMenuItem["Link URL"].ToString();
                            string subID = subMenuItem["Link ID"].ToString();

                            _item2 = new System.Web.UI.WebControls.MenuItem(subtitle, "", "", suburl);

                            SPQuery level3query = new SPQuery();
                            //level3query.Query = "<OrderBy><FieldRef Name='Link_x0020_Order' /></OrderBy><Where><And><Eq><FieldRef Name='Item_x0020_Level' /><Value Type='Choice'>Level 3</Value></Eq><Eq><FieldRef Name='Display' /><Value Type='Choice'>Yes</Value></Eq></And></Where>";
                            level3query.Query = "<OrderBy><FieldRef Name='Link_x0020_Order' /></OrderBy><Where><And><Eq><FieldRef Name='Item_x0020_Level' /><Value Type='Choice'>Level 3</Value></Eq><Eq><FieldRef Name='Display0' /><Value Type='Choice'>Yes</Value></Eq></And></Where>";
                            SPListItemCollection level3items = spCascadingNav.GetItems(level3query);

                            foreach (SPListItem sub3MenuItem in level3items)
                            {
                                string sub3parentID = " ";
                                if (sub3MenuItem["Parent ID"] != null)
                                {
                                    sub3parentID = sub3MenuItem["Parent ID"].ToString();
                                }
                                else { sub3parentID = "None"; }
                                if (sub3parentID == subID)
                                {
                                    string sub3title = sub3MenuItem["Title"].ToString();
                                    string sub3url = sub3MenuItem["Link URL"].ToString();

                                    _item3 = new System.Web.UI.WebControls.MenuItem(sub3title, "", "", sub3url);
                                    _item2.ChildItems.Add(_item3);
                                }
                            }
                            _item.ChildItems.Add(_item2);
                        }

                    }
                    _menu.Items.Add(_item);

                    Controls.Add(_menu);
                }
            }
            catch (Exception ex)
            {
                Controls.Add(new LiteralControl("An error has occured with this web part.  Please contact your system administrator and relay this error message: " + ex.Message));
            }
            finally
            {
                if (thisWeb != null)
                    thisWeb.Dispose();
            }

        }
    }
}


3 Changes to be done in the master page of the application.

Deploye your web part and make some changes in the master page of the application the application in the sharepoint designer 2010 and open the master page of the application and add the following tag in the top

<%@ Register TagPrefix=”customMenu”  namespace=” MenuWebPart”   assembly=” MenuWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=”65ac12bd34er8583″  %>


as Images Displayed below




and add the following tag in the body part of the master page as displayed below

< customMenu: MenuWebPart  runat=”server” id=”customMenu” Set_AdminList=”[type_list_Name_of_Menu]/ CustomMenu” __WebPartId=”{69ER54DE-2SFS-8581-A3C5-DD45S54SD5}” />



If your list name in the sharepoint site is  CustomMenu as displayed below then

=”[type_list_Name_of_Menu]”  instead this type the name as CustomMenu

I will also thank to the owner of link


http://cregan.wordpress.com/2008/05/09/wss-navigation-flyouts-security-trimming-custom-nav-items/