Tuesday 30 December 2014

Do not allow Paste any non alphanumeric characters

I don’t want user to allow pasting of any non Alphanumeric characters on a text box.

function funAlpha()
{
  var otxt=document.getElementById('txtName'); 

var val=otxt.value;

 for(i=0;i
   {
     var code=val.charCodeAt(i);
     if(!(code>=65 && code<=91) && !(code >=97 && code<=121) && !(code>=48 && code<=57))
         { otxt.value=""; return ; }    

   }

}

Friday 12 December 2014

implement idisposable in c# example

static void Main(string[] args)
{
    using (UsingKeyword obj = new UsingKeyword())
    {
       Console.WriteLine(obj.add());
    }
    Console.Read();
}


 Now if we need to perform the clean up using while using our object and facilitate all the above mentioned functionalities we need to implement the IDisposable pattern. Implementing IDisposable pattern will force us to have a Dispose function.
Secondly if the user want to use the try-finally approach then also he can call this Dispose function and the object should release all the resources. 
Lastly and most importantly, lets have a Finalizer that will release the unmanaged resources when the object goes out of scope. The important thing here is to do this finalize only if the programmer is not using the 'using' block and not calling the Dispose explicitly in a finally block.


namespace BasicCsharp
{
    public class UsingKeyword : IDisposable
    {
        public UsingKeyword()
        {
        }

        public int add()
        {
            return 10 + 10;
        }


        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        private IntPtr handle;
        private Component component = new Component();
        private bool disposed = false;


        public UsingKeyword(IntPtr handle)
        {
            this.handle = handle;
        }


        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                    component.Dispose();
                CloseHandle(handle);
                handle = IntPtr.Zero;
                disposed = true;

            }
        }

        [System.Runtime.InteropServices.DllImport("Kernel32")]
        private extern static Boolean CloseHandle(IntPtr handle);
    }

}

Thursday 27 November 2014

How to create Customize permission levels SP2010

let’s run through the steps:
  1. From the site collection click ‘Site Actions’
  2. Click ‘Site Settings’
  3. Under ‘Users and Permissions’ click ‘Advanced Permissions’
  4. You will then see a list for permission level group
  5. Select the ‘Settings’ drop down.
  6. Click ‘Permission Levels’
  7. Click ‘Add a Permission Level’
  8. You will then be able to create your own security group.
Below is a list of permissions that can be set. Please note that selecting one may also result in others being selected because they are required as part of your selection
List Permissions:
  • Manage Lists – create and delete lists, add or remove columns in a list, and add or remove public views of a list.
  • Override Check Out – discard or check in a document that is checked out to another user.
  • Add Items – add items to lists, add documents to document libraries, and add Web discussion comments.
  • Edit Items – edit items in lists, edit documents in document libraries, edit Web discussion comments in documents, and customize Web Part Pages in document libraries.
  • Delete Items – delete items from a list, documents from a document library, and Web discussion comments in documents.
  • View Items – view items in lists, documents in document libraries, and view Web discussion comments.
  • Approve Items – approve a minor version of a list item or document.
  • Open Items – view the source of documents with server-side file handlers.
  • View Versions – view past versions of a list item or document.
  • Delete Versions – delete past versions of a list item or document.
  • Create Alerts – create e-mail alerts.
  • View Application Pages – view forms, views, and application pages. Enumerate lists.
Site Permissions:
  • Manage Permissions – create and change permission levels on the Web site and assign permissions to users and groups.
  • View Usage Data – view reports on Web site usage.
  • Create Subsites – create subsites such as team sites, Meeting Workspace sites, and Document Workspace sites.
  • Manage Web Site – grants the ability to perform all administration tasks for the Web site as well as manage content.
  • Add and Customize Pages – add, change, or delete HTML pages or Web Part Pages, and edit the Web site using a Windows SharePoint Services-compatible editor.
  • Apply Themes and Borders – apply a theme or borders to the entire Web site.
  • Apply Style Sheets – apply a style sheet (.css file) to the Web site.
  • Create Groups – create a group of users that can be used anywhere within the site collection.
  • Browse Directories – enumerate files and folders in a Web site using SharePoint Designer and Web DAV (Distributed Authoring and Versioning) interfaces.
  • View Pages – view pages in a Web site.
  • Enumerate Permissions – enumerate permissions on the Web site, list, folder, document, or list item.
  • Browse User Information – view information about users of the Web site.
  • Manage Alerts – manage alerts for all users of the Web site.
  • Use Remote Interfaces – use SOAP, (Simple Object Access Protocol) Web DAV, or SharePoint Designer interfaces to access the Web site.
  • Use Client Integration Features – use features that launch client applications. Without this permission, users will have to work on documents locally and upload their changes.
  • Open – allows users to open a Web site, list, or folder in order to access items inside that container.
  • Edit Personal User Information – allows a user to change his or her own user information, such as adding a picture.
Personal Permissions:
  • Manage Personal Views – create, change, and delete personal views of lists.
  • Add/Remove Personal Web Parts – add or remove personal Web Parts on a Web Part Page.
  • Update Personal Web Parts – update Web Parts to display personalized information.

Saturday 15 November 2014

Auto select file in Solution explorer from it is open tab in VS2010

Tools ->Option -> project and solution -> Track active item in solution explorer

Step 1: Goto Tool menu and click Option ..

Step 2:  project and solution -> Track active item in solution explorer

Step 3: Output


Programmatically Read Version of a Sharepoint List

Here I will show how you can read all versions of a list item programmatically. As you know, in SharePoint you can turn on the versioning for a list so whenever you modify an item in your list, it keeps track of all your changes so you can revert back to a specific version.


Thursday 2 October 2014

BUILDING AND USING MS PROJECT 2010 PROXY ASSEMBLY FOR WCF PSI SERVICE

To do the task of integrating Microsoft Dynamics NAV 2009 R2 and MS Project Server 2010 I have decided to use WCF interface. WCF interface is provided by PSI (Project Server Interface) which has both ASMX object model and WCF object model implemented.
There are three options for communicating with WCF interface of MS Project Server:
  1. Compiling ProjectServerServices.dll PSI proxy assembly.
  2. Add a PSI proxy source code to the Visual Studio solution.
  3. Add a service reference by using Visual Studio.
I have decided to use the first option and compile ProjectServerServices.dll proxy assembly.

Project 2010 SDK

First you need to download and install Project 2010 SDK from Microsoft Download site http://www.microsoft.com/en-us/download/details.aspx?id=15511
After you have installed Project 2010 SDK you need to go to the installation folder. In my case that was folder: C:\Program Files (x86)\Microsoft SDKs\Project 2010\Documentation\Intellisense\WCF. Unpack the Source.zip file, found in that folder, so you get the Source subfolder containing C# source files.
Next, you need to start CompileWCFProxyAssembly.cmd to create ProjectServerServices.dll file. The best way to do it is to open Command prompt with administrative privileges (Start->All Programs->Accessories->Command prompt then right click and select Run as administrator), then cd to the C:\Program Files (x86)\Microsoft SDKs\Project 2010\Documentation\Intellisense\WCF and then run CompileWCFProxyAssembly.cmd.

Note: You need to change the path of sn (sn.exe) to the location of Windows SDK in CompileWCFProxyAssembly.cmd. In my case that was C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\x64\sn.exe.

After the script has run you should have ProjectServerServices.dllin this folder.

Visual Studio

In Visual Studio you shoud add reference by clicking right mouse button on Reference folder in your C# project then select Add reference… option, then select Browse on the left hand side of the Reference Manager window and click Browse… button on the lower side of the window. Navigate to C:\Program Files (x86)\Microsoft SDKs\Project 2010\Documentation\Intellisense\WCF\ProjectServerServices.dllfile and click Add button. Click OK to close the Reference Manager window.

project server 2010 requires at least microsoft internet explorer 7.0

My IE to version 10 for Windows2008 r2. Since then, I was not able to access my project centre. I kept getting this error message
 I tried setting the compatibility mode for this PWA site. Note: You can do this via IE Tools.

Flow below steps 
  • Open Internet Options from Tools menu.
  • Click on Security tab in internet option box.
  • Click on Local Intranet, Then click on Sites button. You will get again a box where you have to click on Advanced button.
  • Put project server url here and then click on Add button.
  • Now close all boxes and Refresh your IE.



Thursday 4 September 2014

Text Box Characters Counter using Javascript

In forms when using text boxes or text areas with limited character length (usually needed for forms that submit data to a database) it is always a good idea to tell the user how many characters they have remaining. This javascript snippet is especially useful for textarea fields since they can't be assigned a text limit in HTML but can be restricted using this code.
The following example shows how you can do this. This is a very simple and cute idea to help the user know exactly how many characters can be typed further. Do these small add-ons to your forms and they will look really professional.

 
<html>
  <head>
    <script src="http://code.jquery.com/jquery-1.5.js"></script>
    <script>
    function countChar(val) {
        var len = val.value.length;
        if (len >= 100) {
          val.value = val.value.substring(0, 100);
        } else {
          $('#charNum').text(100 - len);
        }
      };
    </script>
  </head>

  <body>
    <textarea id="field" onkeyup="countChar(this)" ondrop="countChar(this)" onfocus="countChar(this)" onload="countChar(this)"  ></textarea>
    <div id="charNum1">(Maximum characters:<span id="charNum" > 100</span>)</div>
  </body>

</html>

Text box allow only Alphabets

Introduction 
Here I will show how to use Javascript to allow only alphabets in textbox or how to make textbox to allow only alphabets using javascript
 
 
<html>
<div>
               <script type="text/javascript">
                   function IsAlpha(e) {
                      // alert(e.keyCode);
                       var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode;

//65 to 90 is Capital letter : 97 to 122 is small letter : 32 is Space  : Delete 127
                       var ret = ( (keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <=

           122) || (keyCode == 32) || (keyCode == 08) || (keyCode == 127));
                      // document.getElementById("error").style.display = ret ? "none" : "inline";
                       return ret;
                   }
        </script>
            <input type="text" id="text1" onkeypress="return IsAlpha(event);" ondrop="return false;"
        onpaste="return false;" />

   
        </div>
</html>

Sunday 24 August 2014

Date format using Javascript


Date format mm / dd / yyyy. We can chage format also.




window.onload = function currentDate()
{
var today = new Date();
    var dd = today.getDate();
    var mm = today.getMonth()+1; //January is 0!

    var yyyy = today.getFullYear();
    if(dd<10 span="">
        dd='0'+dd
    }
    if(mm<10 span="">
        mm='0'+mm
    }
    var today = mm+'/'+dd+'/'+yyyy;
$("#datetoday").html(today);
}

Digital Clock

This is a pretty cool way to display the time on your web page using jQuery to get the current time and then refresh the clock every 1 second.




function Clock ( )     {  

  var currentTime = new Date ( ); 
   var currentHours = currentTime.getHours ( ); 
   var currentMinutes = currentTime.getMinutes ();   


 var currentSeconds = currentTime.getSeconds ( );  

 currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;    

currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;     
  
   var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";   
   currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;     

  currentHours = ( currentHours == 0 ) ? 12 : currentHours;  
 
  var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;     
           $("#clock").html(currentTimeString);
           }


  $(document).ready(function() {
    setInterval('Clock()', 1000);
});