Posts

Showing posts from July, 2011

Optional Parameters and Named Arguments in Framework 4

Image
This time I will demonstrate another nice feature in the framework 4 C # 4.0 now supports using Optional Parameters with Methods, Constructors, and Indexers . Earlier versions of the framework, create a mountain default variable is actually needs to create two methods.   private static double GetPriceIncludesVAT( double p, double vat)   {      return p * vat;   }   private static double GetPriceIncludesVAT( double p)   {      return GetPriceIncludesVAT(p, 16.5);   } Today, with the framework 4, C #, we can give a default (like VB) to methods. Another nice thing we got, it Named Arguments . So that the code will organized - we can be the names in a methods call. Look for the following example:   double priceWith15VAT = GetPriceIncludesVAT(vat: 15, p: 50); Here is the Code: using System; namespace OptionalParm {     class Program ...

Get a SharePoint List of Client Object Model in SharePoint 2010

Image
One serious benefits provides us with the code in SP2010 is the  Client Object Model Client Object Model gives us the client-side API . Example: Opens a console project We will Add Reference the DLL to the following: Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll form 14Hive\Isapi folder. Now type the following code: using System; using System.Linq; using MyClientOM = Microsoft.SharePoint.Client; namespace TestClientOM {     class Program     {         static void Main( string [] args)         {             string myUrl = " http://mysite.com/ " ;             using (MyClientOM. ClientContext ctx = new MyClientOM. ClientContext (myUrl))             { ...

Get Alternate Access Mappings by code

At the time I explained to you what problems occur when the wrong set of Alternate Access Mappings . This time I will show you how to get the Alternate Access Mappings by code. The following function returns an array of links for Current Web Application - Alternate Access Mappings . ///   <summary> ///  Create a list with the alternate access mapping urls ///   </summary> ///   <returns></returns> private   List < Uri > GetCurrentAlternateAccessMappingsUrls() {      List < Uri > alternateUrls =  null ;      // Make sure anonymous users can access the web application properties      SPSecurity .RunWithElevatedPrivileges( delegate ()     {         alternateUrls =  new   Lis...