Posts Tagged ‘C#’

Authentication Client Object Model (CLR)

In my previous post i talked about the SharePoint client object model

And some good topics and how to get up to speed with using it..

Today i ll write about the security in the Client object model…

I didn’t find many topics talking about it is still beta any way…

If you look in the CLR page on MSDN you will find out that it have three properties

AuthenticationMode

Credentials

FormsAuthenticationLoginInfo

The ClientRuntimeContext . Authentication Mode can have three values Anonymous , Forms Authentication

And default which is Windows Authentication

You can use the property FormsAuthenticationLoginInfo to set your forms authentication user name and password

Example

SP.FormsAuthenticationLoginInfo 

formsLoginInfo = new SP.FormsAuthenticationLoginInfo("TobiasZimmergren", "Secret Password");

ctx.AuthenticationMode = SP.ClientAuthenticationMode.FormsAuthentication;

ctx.FormsAuthenticationLoginInfo = formsLoginInfo;

 

nd you can use the Credentials property for the windows 

uthentication

xample 

 

 

g (clientContext = new ClientContext(siteUrl))

{

NetworkCredential credential = new NetworkCredential("username", "password", "domain");

clientContext.AuthenticationMode = ClientAuthenticationMode.Default;

clientContext.Credentials = credential;

}

Remember that you can configure the authentication and security for the SharePoint application from

The central administration site

Choose application management – Manage Web Application

Select your web application and click Authentication provider

Click the default zone properties



You will find the property Client Object Model Permission Requirement you can check or uncheck it according to your scenario

Hope this topic was useful and had a good explanation … I spent some time trying to find out about that…

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

What is New In C# 2.0 , 3.0 , 3.5, 4.0 ( road map)

What is New In C# 4.0

Dynamic lookup

dynamic d = 7;

d = “Abdel-Rahman”;

Named and optional parameters
public void M(int x, int y = 5, int z = 7);

M(1, 2, 3); // ordinary call of M 

M(1, 2); // omitting z – equivalent to 

M(1, 2, 7) 

M(1); // omitting both y and z – equivalent to M(1, 5, 7) 

 

M(1, z: 3); // passing z by name 

M(x: 1, z: 3); // passing both x and z by name 

M(z: 3, x: 1); // reversing the order of arguments

COM specific interop features

This means that you can easily access members directly off a returned object, or you can assign it to a strongly typed local variable without having to cast. To illustrate, you can now say

excel.Cells[1, 1].Value = "Hello"; 

 

// instead of 

 

((Excel.Range)excel.Cells[1, 1]).Value2 = "Hello"; 

 

Excel.Range range = excel.Cells[1, 1]; 

 

// instead of 

 

Excel.Range range = (Excel.Range)excel.Cells[1, 1];

Variance

// ToDo : 1.0 Add Example.

What is New In C# 3.0 , C# 3.5

you can see my old post about C# 3.0 here , but i think i ll write about it here in more details.

Automatic  Properties
public int MyProperty { get; set; }

Implicitly Typed Local Variables
var n = 5;

var s = “LINQ rules”;

var b = new[] { 1, 1.5, 2, 2.5 };

var c = new[] { "hello", null, "world" };

Anonymous Types

var anonType = new {X = 1, Y = 2};

var NewTempClass = new {FirstName = "name" , Age = 32 };

string x = NewTempClass.FirstName;

Object Initializes
Contact contact = new Contact { LastName = “Magennis”, Age = 9 };

Collection Initializers
List<int> digits = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

List<Contact> contacts = new List<Contact>

{ new Contact {LastName = “Doherty”, DOB =55},new Contact {LastName = “Wilcox”, DOB = 66} };

Extension Methods

They made a new generic methods so you can extend the functionality of any class you want

public static int NewExtensionMethod(this string s) {return Int32.Parse(s); }

Partial Methods
Query Expressions
var result = from item in List.items Where item.Title = ”Abdel”

select item;

Lambda Expressions
IEnuerable <Person> results = People.Where( P => P.LastName ="Abdel");

double Averageage = People.Average(P => P.Age);

Expression Trees

 

What is New In C# 2.0

Generics
class BaseNode { }

class BaseNodeGeneric<T> { }

class NodeConcrete<T> : BaseNode { }

class NodeClosed<T> : BaseNodeGeneric<int> { }

class NodeOpen<T> : BaseNodeGeneric<T> { }

class BaseNodeMultiple<T, U> { }

class Node4<T> : BaseNodeMultiple<T, int> { }

class Node5<T, U> : BaseNodeMultiple<T, U> { }

class SuperKeyType<K, V, U>  where U : System.IComparable<U>  where V : new() { }

static void Swap<T>(ref T lhs, ref T rhs)

class SampleClass<T> 

{ 

 void Swap(ref T lhs, 

ref T rhs) { } 

}

Iterators
  • An iterator is a section of code that returns an ordered sequence of values of the same type.

  • An iterator can be used as the body of a method, an operator, or a get accessor.

  • The iterator code uses the yield return statement to return each element in turn. yield break ends the iteration. For more information, see yield.

  • Multiple iterators can be implemented on a class. Each iterator must have a unique name just like any class member, and can be invoked by client code in a foreach statement as follows: foreach(int x in SampleClass.Iterator2){}

  • The return type of an iterator must be IEnumerable, IEnumerator, IEnumerable<T>, or IEnumerator<T>.

The yield keyword is used to specify the value, or values, returned. When the yield return statement is reached, the current location is stored. Execution is restarted from this location the next time the iterator is called.

Iterators are especially useful with collection classes, providing an easy way to iterate non-trivial data structures such as binary trees.

Partial Classes
Nullable Types

example int? x = null; int y = x ?? -1;

Use the System.Nullable.GetValueOrDefault

The syntax T?

Anonymous Methods

Del d = delegate(int k) { /* … */ };

Static Classes
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

QuickLaunch Menu MOSS C#

Very clever link that Describe all about Modifying The menus in MOSS From code behind Quick Launch

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

XSD To CS Tool

Create To the XSD design You Want and then use this tool to generate the code behind and classes very useful when trying to serialize objects to be passed in webservices.

Open your Visual Studio Select Tools > External Tools then Click ADD

 

Title : XSD generation

Command : system Drive:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\xsd.exe

Arguments : /nologo /c /n:CB.Booking.ServiceModel.$(ItemFileName) $(ItemPath)

Initial Directory : $(ItemDir)

Check Use Out Put window Option

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

Object Serialize TO Xml

Two Functions to Serialize and detribalize any objects to and from xml

 

 

private string Serialize(object obj) 

{ 

     if (obj == null) { return null; }

     XmlSerializer s = new XmlSerializer(obj.GetType()); 

     TextWriter w = new StringWriter(); 

     s.Serialize(w, obj); 

     w.Close();

     return w.ToString(); 

}

 

 

public static object Deserialize(Type type, string xml) 

{ 

 

 if (string.IsNullOrEmpty(xml)) 

 { 

     return Activator.CreateInstance(type); 

 } 

 

    XmlSerializer s = new XmlSerializer(type); 

    TextReader tr = new StringReader(xml); 

    return s.Deserialize(tr); 

}

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

New In C# 3.0

Automatic  Properties

generates a temp private variables to assign properties

Old Code
private int myProperty;

 

public int MyProperty {

 

get{return myProperty} ;

 

set {myProperty = value }; }

New Code
public int MyProperty { get; set; }

 

Implicitly Typed Local Variables

Replaced the intializers (string,int,..) to be of general type Var how ever any defined var variable must be assigned to value from which the compiler knows the type of the new declared variable

Old Code
int n = 5;

 

string s = “LINQ rules”;

 

int[] nums = new int[] {1, 2, 3};

New Code
var n = 5;

 

var s = “LINQ rules”;

 

var nums = new int[] {1, 2, 3};

Implicitly Typed Local Variables

Old Code
int[] a = new int[] { 1, 10, 100, 1000 };

 

double[] b = new double[] { 1, 1.5, 2, 2.5 };

 

string[] c = new string[] { "hello", null, "world" };

New Code
var a = new[] { 1, 10, 100, 1000 };

 

var b = new[] { 1, 1.5, 2, 2.5 };

 

var c = new[] { "hello", null, "world" };

Anonymous Types

A New Fast way of declaring types.

Old Code
class ConcreteType {

 

private int _x;

 

private int _y;

 

public int X { get { return _x; } set { _x = value; } }

 

public int Y { get { return _y; } set { _y = value; } }

 

}  

 

ConcreteType conType = new ConcreteType();

 

contype.X = 1; contype.Y = 2;

New Code
var anonType = new {X = 1, Y = 2};

 

or

 

var NewTempClass = new {FirstName = "name" , Age = 32 };

Object Initializers

A New Fast way of intializing objects .

Old Code
Contact contact = new Contact();

 

contact.LastName = “Magennis”;

 

contact.DateOfBirth = new DateTime(1973,12,09);

New Code
Contact contact = new Contact { LastName = “Magennis”, DateOfBirth = new DateTime(1973,12,09) };

Collection Initializers

A New Fast way of intializing Collections and list.

Old Code
List<int> digits = new List<int> ();

 

digits.add(0);

 

digits.add(1);

 

digits.add(2);

 

....

New Code
List<int> digits = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

 

more over

 

List<Contact> contacts = new List<Contact>

 

{ new Contact {LastName = “Doherty”, DOB =55},

 

new Contact {LastName = “Wilcox”, DOB = 66} };

Extension Methods

They made a new generic methods so you can extend the functionality of any class you want.

New Code
 

using Acme.Utilities;string Str = "New Test";

int i = Str.NewExtensionMethod();

 

namespace Acme.Utilities 

{

 

 public static class Extensions

 {

    public static int NewExtensionMethod(this string s)

    {

        return Int32.Parse(s); 

    }

 } 

}

Partial Methods

Old Code

ToDo:

New Code

TODO:

Query Expressions

Old Code
ArrrayList myquery =  new ArrayList();

 

string[] Files = Directory.GetFiles(@"c:\");

 

foreach(string Str in Files)

 

{

 

    if(Str.EndWith(".Bat")

    

    myquery.add(str);

 

}

New Code
var myquery = from i in Directory.GetFiles(@"c:\")

 

                        Where i.EndWith(".Bat")

 

                       Selecet i;

Lambda Expressions

Old Code
IEnuerable <Person> results = People.Where( 

 

                    delegate(Person P)

 

                    {return P.LastName = "Abdel";}

 

                   );

double Averageage = People.Average( 

 

                    delegate(Person P)

 

                    {return P.Age;}

 

                   );

New Code
IEnuerable <Person> results = People.Where( P => P.LastName ="Abdel");

 

double Averageage = People.Average(P => P.Age);

Expression Trees

Old Code

ToDo:

New Code

TODO:

RESOURCES :

Videos

Hooked on LINQ

C# 3.0

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

Create JavaScript From Code Behind

After You Create your JavaScript String In The Code Behind  go to the page load event and this to register the JavaScript to your page

Page.RegisterStartupScript("ScriptString", ScriptString);

 

as I said in my last post some times the id you assign for a control is not always the actual id given to it on the client side

so if you are making JavaScript and using controls id make sure to use control.ID

To change an html

document['docimagename'].src = '/images/imagename.gif'

docimagename is the name attribute of the image

Hide Control

document.getElementById('ControlID').style.visibility = 'hidden';

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

Create Controls From Code Behind

I was Creating control that had fields created dynamically according to data passed

and according to the controls created some java scripts need to be added with them

and here are some tips I learned

the id you assign to the control in runtime some times is not the actual id of the control in the html client side code specially when this control created inside A Custom User Control..

So in order to get the actual client side control id to use it in JavaScript code use Control.ClientID to get it.

if you added an html control that runat server  in a Custom user control

this html control wont appear in the C# code behind code unless you add some thing like that.

protected global::System.Web.UI.HtmlControls.HtmlGenericControl MainDiv;

To render html code in a div that run at server use the following

MainDiv.InnerHtml = HtmlString;

 

you can create asp control and render it into html string using

StringWriter sw = new StringWriter();

control.RenderControl(new HtmlTextWriter(sw));

MainDiv.InnerHtml = sw.ToString();

 

How ever if the rendered asp control have some event handlers

those handlers wont be invoked for some strange reason I didn’t find out it yet.

 

but you can create controls with event handlers in other way by

using System.Web.UI.WebControls.Table;

usingSystem.Web.UI.WebControls.TableRow;

using System.Web.UI.WebControls.TableCell;

 

 

and finally after creating the control from code behind add it the controls of the cell …

TableCell.controls.add(control);

TableRow.cells.add(TableCell);

Table.Rows.add(TableRow);

 

some Times you need to add some tags like style and things like that to the control this can done using

Control.Attributes.add(StringKey,StringValue);

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

Cancel Validation

some times when you are using the asp Validations and want to add cancel button to form

when this button is clicked the from is supposed to cancel all the registration operation still the required field validation shows up asking for a field value

Solution : set the Cancel button Property Cause validation to False

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

Visual Studio Short Cuts

If you want all the Visual Studio keyboard Shortcuts

for Microsoft® Visual C#® Default Keybindings Click C#

for Microsoft® Visual Basic® Default Keybindings Click VB

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

 

View Abdel-Rahman Awad's profile on LinkedIn

Archives

 

Rss Feed Tweeter button Facebook button Linkedin button Delicious button Digg button