Search This Blog

Total Pageviews

Tuesday, March 6, 2012

Client Object Model SDK

CAML Query Helper Class

CAMLManager mgr = new CAMLManager();

mgr.QueryGroups.Add(new QueryGroup("Title", Types.FieldTypes.Text, Types.QueryTypes.Eq, "A Title"));
mgr.QueryGroups.Add(new QueryGroup(Types.JoinTypes.Or, "Title", Types.FieldTypes.Text, Types.QueryTypes.Eq, "Another Title"));

mgr.QueryGroups.Add(new QueryGroup(Types.JoinTypes.And, QueryGroup.MergeTypes.Contain, "Total", Types.FieldTypes.Number, Types.QueryTypes.Geq, "2"));

string caml = mgr.GetCAML();

Will provide the following:
        <FieldRef Name="Title" /><Value Type="Text">A Title</Value>
        <FieldRef Name="Title" /><Value Type="Text">Another Title</Value>
      <FieldRef Name="Total" /><Value Type="Number">2</Value>

Sunday, March 4, 2012

Membership.CreateUser(Loginid, Password, Emailid);

Error : Object Reference not to set an object

1)Continue to rely on SPClaimsAuthMembershipProvider and obtaining HttpContext.Current

Just instantiate the HttContext.Current If it is null:

if (HttpContext.Current == null)
HttpRequest request = new HttpRequest(String.Empty, sp_web.Url, String.Empty);
HttpContext.Current = new HttpContext(request, new HttpResponse(new StringWriter()));

If you instantiated new HttpContext, it would be good to reset it at the end of your methods back to null. Just make sure this happens only if HttpContext.Current was null at the beginning.

2)Working with the SqlMembershipProvider and forgetting about HttpContext.Current issue

What we need is to get the SqlMembershipProvider from registered providers and to start using it.
SqlMembershipProvider sqlMembershipProvider = (SqlMembershipProvider)Membership.Providers["FBAMembershipProvider"];

Bear in mind that you should put the name as it is in your web.config file.

Friday, March 2, 2012

How to store the sharepoint List or List Item within the recycle bin of the site while deleting it programmatically ?

Whenever we delete a sharepoint list or list item from the User Interface it get stored within the recycle bin of the site. But when we delete it programmatically it get's deleted permanently.

So what we can do to store the List or List Item within the recycle bin while deleting it programmatically ?

Generally we use the list.Delete() or item.Delete() method to delete the list or item.
Instead of using the Delete() method we can use the Recycle() method i.e list.Recycle() or item.Recycle(). This will store the item within the recycle bin.