Thursday, August 8, 2013

HTML Tips

1. How to align two elements on the same line without changing HTML

Using display:inline-block
#element1 {display:inline-block;margin-right:10px;} 
#element2 {display:inline-block;} 

2.







Monday, July 22, 2013

Various options to store your SharePoint Solution’s Configuration Data.


The various options are : -
  1. Code
  2. web.config
  3. SharePoint List
  4. External Data Source
  5. Property Bag - 
  6. Hierarchical Object Store


Ref:
1. http://blogs.msdn.com/b/zwsong/archive/2012/03/27/where-should-you-store-your-sharepoint-solution-s-configuration-data.aspx - Good one with comparison. Do read the comments.

2. Hierarchical Object Store in SharePoint 2010 - more info on how to use the same.

Wednesday, July 3, 2013

Sharepoint 2010 Events

New Events in SharePoint Foundation 2010
Two new Add events have been provided for SharePoint lists – that is, for SPList objects:

In addition to these Add events, two Delete events have also been added to SharePoint lists:

New events on Sharepoint Sites

New Synchronous After Events
The default synchronization behavior is synchronous for before events and asynchronous for after events. Also available is a new property on the SPEventReceiverDefinition base class called Synchronization. This property has get and set methods to retrieve and set the SPEventReceiverSynchronization enumeration value. This enumeration provides a value called Default to support backward compatibility.


New Event Binding Functionality in SharePoint Foundation 2010
The ability to bind events at the scope of the site collection (SPSite), as well as giving you the ability to bind XML event receivers that are scoped to the individual site (SPWeb).

SPSite-Level Binding
   SharePoint Foundation 2010 supports an SPSite-level event receivers collection. Like other event receiver collections, this one accepts bindings from SPWebEventReceiver, SPListEventReceiver, and SPItemEventReceiver objects. All of these event types can be scoped to the site collection level (that is, SPSite). However, an SPEmailEventReceiver object does not work at the site collection level because the way that this object is implemented.

SharePoint Foundation 2010 supports binding XML event receivers at the scopes of both SPWeb and SPSite instances by using the <Receivers> tag. When a SharePoint Feature is scoped to the site collection level, a <Receivers> tag is potentially ambiguous. The tag can indicate either site-wide event binding or event binding for the top-level site. Note, however, that the default behavior is to scope to the site level. Therefore, when you scope a Feature to the site collection level, use the attribute named Scope to specify the intended scope.

SharePoint Foundation 2010 supports event binding based on the SPItemEventReceiver event receiver by using semantics of the ListTemplateId property. This approach creates an event receiver definition that is scoped to the list as the list is created. SP supports event binding that is based on the SPItemEventReceiver object in the XML of a specified content type.


SP provide the identity (ID) of the originating user and then let the event receiver implementer respond as appropriate.
SharePoint Foundation 2010 also introduces a new property called OriginatingUserToken on the SPEventPropertiesBase class that
returns the ID of the originating user.

 Event code should check for this user by ID, and, optionally, perform behaviors that can potentially cause unexpected effects by using an impersonated site collection with the token of that originating user.

In some scenarios, for example, when an active workflow has code that is running with elevated privileges, the code runs in the context of the system account. But in this scenario, when event receiver code needs to run with the credentials of the originating user, SharePoint Foundation 2010 allows you to undo the reversion using the above feature.

Redirect to URL in SharePoint Foundation 2010

Microsoft SharePoint Foundation 2010 now allows event receivers to provide a redirection URL to provide custom messages through the user interface (UI). The redirect URL feature works with all pre-event receiver types (such as SPWebEventReceiver, SPListEventReceiver, and SPItemEventReceiver) in cases where the action is being cancelled. To support the new user interfaces, SharePoint Foundation 2010 added the CancelWithRedirectUrl field to values in the SPEventReceiverStatus enumeration  (values -CancelNoError,    CancelWithError,    CancelWithRedirectUrl,    Continue ). CancelWithRedirectUrl allows you to specify a redirect URL for a Web browser UI. Use the URL that is specified by the RedirectUrl property of the SPEventPropertiesBase object to navigate to alternate pages. This URL should be a server-relative URL, and cannot contain ECMAScript (JavaScript, JScript).



Tuesday, January 29, 2013

Powershell Quick Start



Get-Alias- complete list of available aliases

Get-Command - that returns a list of all the PowerShell cmdlets available to you

Format-List : is a cmdlet that takes information passed to it and then outputs that information in list view (that is, property values are displayed on separate lines rather than as columns in a table).
Eg:PS C:\scripts> Get-Command | Format-List

Format-Table : cmdlet can take pretty much any information and display it as a table rather than a list.

set-location c:\Windows

Get-ChildItem C:\Scripts –recurse

Set-ExecutionPolicy RemoteSigned
To run scripts from within Windows PowerShell you will need to change your security settings; by default, PowerShell only runs scripts signed by a trusted authority.

Get-Process
To get information about the properties and methods of an object retrieve an instance of that object and then “pipe” the object to the Get-Member cmdlet. For example, this command returns the properties and methods available when working with processes:  eg Get-Process | Get-Member

Get-Process 
To work with or display specified properties of a collection, pipe the returned results to the Select-Object cmdlet:
Eg Get-Process | Select-Object Name, Company


Where-Object {$_.Length -gt 200KB} | Sort-Object Length
To filter and sort objects . Sort-Object should typically appear on the right-hand side of a pipeline.
Eg1:
Get-ChildItem C:\Scripts | Where-Object {$_.Length -gt 200KB} | Sort-Object Length
eg2: Get-Service | Sort-Object Status | Format-Table
eg:3: $a = (Get-Process | Sort-Object ID)
 
You have a variable $a that contains a collection of data. You can sort that data, and sidestep the pipeline altogether, by using a command like this: eg: Sort-Object -inputobject $a



Some more must read for quick start

1)Running powershell
http://technet.microsoft.com/en-us/library/ee176949.aspx
 
2)Getting started with powershell
http://technet.microsoft.com/en-us/library/ee177003.aspx

and other links under those section of above links.


More references:




1) Windows PowerShell Quick Reference

http://www.microsoft.com/en-us/download/details.aspx?id=7097


2) Learn powershell
   http://blog.endjin.com/2012/03/an-omega-geeks-guide-to-learning-powershell/

3) Windows PowerShell Graphical Help File

Some issues and Solution
1)Issue unable to load snapin
Sol : some snapins are registered for 64 bit
in that use try powershell.exe at  C:\Windows\SysWOW64\WindowsPowerShell\v1.0 –
& some might work only for 32 bit then try powershell at C:\Windows\System32\WindowsPowerShell\v1.0)






Wednesday, January 23, 2013

Export grid to excel Asp.net


Good reference
http://mattberseth.com/blog/2007/04/export_gridview_to_excel_1.html 

Tuesday, January 22, 2013

Programming SCCM , Active directory using .Net



Some tools which help this development

1.The WMI Code Creator tool allows you to generate VBScript, C#, and VB .NET code that uses WMI to  complete a management task such as querying for management data, executing a method from a WMI class, or receiving event notifications using WMI.
 download at  http://www.microsoft.com/en-us/download/details.aspx?id=8572


2. webemtest



Refresh Package Source Distribution points using C#


Below is the code to update Refresh Package source distribution points using C# 


 public static string RefreshPackageDPs(string pkgID)
        {
 
            string result = null;
            List<string> dpstatusinfo = new List<string>();
            try
            {

//code to connect to SCCM
               ManagementScope scope;
ConnectionOptions connOptions = new ConnectionOptions()
                                   {
                                       Username = userName,
                                       Password = userPassword,
                                       Impersonation = ImpersonationLevel.Impersonate //Identify- recommended level for WMI Calls
                                       ,
                                   };//Timeout= TimeSpan.MaxValue
                    scope = new ManagementScope(wmiNameSpace, connOptions);
 scope.Connect();

//Code to Refresh the DP's
                ObjectQuery query = new ObjectQuery("SELECT *  FROM SMS_DistributionPoint WHERE PackageID='" + pkgID + "'");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
 
 
                foreach (ManagementObject queryObj in searcher.Get())
                {   
                    queryObj.SetPropertyValue("RefreshNow", true);
                    queryObj.Put();
                }
 
                result= "All DP's refresh started successfully!";
            }
            catch (ManagementException e)
            {
                result = "An error occurred while refresh package DP's.";

            }
            return result;
        }

Leave me a comment is you need any more info 

Difference between Update Dp's and Refresh Dp's.
Refer - > http://technet.microsoft.com/en-us/library/bb892806.aspx

Thursday, January 10, 2013

Get Username for logged in user Asp.net

The below is when using Windows Authentication using ASp.net

In ASP.NET, please use User.Identity.Name to get the logon user. User.Identity.Name might be empty if Anonymous Authentication is enabled in IIS.
http://msdn2.microsoft.com/en-us/library/system.web.httpcontext.user.aspx
Here is the logical to check if the identity is available.

VB.NET
' Gets the name if authenticated.
If User.Identity.IsAuthenticated Then
    Label1.Text = User.Identity.Name
Else
    Label1.Text = "No user identity available."
End If

C#
' Gets the name if authenticated.
if (User.Identity.IsAuthenticated)
    Label1.Text = User.Identity.Name;
else
    Label1.Text = "No user identity available.";


Environment.UserName is the running thread identity. If you have enabled Impersonation as Mark said, you can find out the returning result will be different. However this requires ASP.NET Impersionation. If you don't need ASP.NET Impersonation and dealing with the thread identity, you can ignore Environment.UserName if and just use User.Identity.Name.

Alternate ways to get username are are
  1. this
.Context.Request.LogonUserIdentity.Name
  • Request.LogonUserIdentity.Name
  • ref: http://forums.asp.net/t/1179997.aspx/1/10


    Asp.net 4 on IIs7


    1. how-to-install-internet-information-services-iis-7-on-windows-7

    ref: http://hrushikeshzadgaonkar.wordpress.com/2010/05/28/how-to-install-internet-information-services-iis-7-on-windows-7/

    2.How to add ASP.NET 4.0 as Application Pool on IIS 7, Windows 7

    http://stackoverflow.com/questions/4890245/how-to-add-asp-net-4-0-as-application-pool-on-iis-7-windows-7

    Monday, January 7, 2013

    Everything SQL Server Compact: SQL Server Compact Private Deployment tweaks

    Method 1:
    this worked for me
    build commands dint work in this




    MEthod 2: dint work dont know why!

    Everything SQL Server Compact: SQL Server Compact Private Deployment tweaks: As a follow up to my previous post about Private Deployment (the concept that you can simply include the SQL Server Compact DLL files with ...

    for SQLCE 3.5 the code to use is
     <bindingRedirect oldVersion="3.5.8080.0" newVersion="3.5.1.0" />


    Sunday, January 6, 2013

    Asp.net 4.0 & HTML 5



    1) Asp.net 4.0 with Visual Studio 2010 is compatible with HTML 5. You can download the Visual Studio Service pack 1 Beta From Here
    for Html 5 and CSS3 intellisense http://www.microsoft.com/en-us/download/details.aspx?id=23691

    2)http://blog.reybango.com/2010/09/21/how-to-create-html5-website-and-page-templates-for-visual-studio-2010/

    Devops links

      Build Versioning in Azure DevOps Pipelines