Tuesday, January 3, 2017

Retrieving Data from a Multi-Authentication Site by Using the Client Object Model and Web Services in SharePoint 2010

link : https://msdn.microsoft.com/en-us/library/office/hh124553(v=office.14).aspx


In this article, I am covering only the most common parts of how to retrieve data from a multi-authentication site by using the client object model and web services; there are multiple twists that can be added. The scenario is to retrieve data from a SharePoint site that is using multiple authentication providers. In this scenario, assume that one of the authentication providers is Windows claims and the other authentication provider is anything else—it could be forms-based authentication or a SAML authentication provider. Often you want to retrieve data from such a site by using either the client object model or SharePoint web services, but you want to use Windows authentication to do so. The problem up to this point has always been that even when you set your Windows credentials on the request, you still get an access denied error when requesting the data.
The resolution to this problem is that, if you want to programmatically access a SharePoint site that uses multiple authentication providers by using a set of Windows credentials, you must add an additional header to your request. The header name must be X-FORMS_BASED_AUTH_ACCEPTED and the value must be f. Adding this header can be a bit complicated for these two common scenarios (that is, using the client object model or web services). The rest of this article explains how to do that and gives some sample code. If you are using the client object model, you must add an event handler for the ExecutingWebRequest event. The following is a code example.



//Create the client context.
ClientContext ctx = new ClientContext(MixedUrlTxt.Text);
//Configure the handler that will add the header.
ctx.ExecutingWebRequest +=
new EventHandler(ctx_MixedAuthRequest);
//Set the Windows credentials.
ctx.AuthenticationMode = ClientAuthenticationMode.Default;
ctx.Credentials = System.Net.CredentialCache.DefaultCredentials;
//Get the web.
Web w = ctx.Web;
//Load lists with all properties. 
var lists = ctx.LoadQuery(w.Lists);
//Execute the query.
ctx.ExecuteQuery();
//Enumerate the results.
foreach (List theList in lists)
{
//Do something with each list.
}


void ctx_MixedAuthRequest(object sender, WebRequestEventArgs e)
{
try
{
//Add the header that tells SharePoint to use Windows authentication.
e.WebRequestExecutor.RequestHeaders.Add(
"X-FORMS_BASED_AUTH_ACCEPTED", "f");
}
catch (Exception ex)
{
MessageBox.Show("Error setting authentication header: " + ex.Message);
}
}

Sunday, April 24, 2016

change bootstrap grid direction dynamically ( ltr to rtl or reverese)

There is a possibility to use bootstrap which it's grid flow order is Rtl if the site language is fa , and use Ltr when the language is English ?
By language , I mean this : www.example.com/en or www.example.com/ar
when it is /en , we must use bootstrap which is Ltr (Left to right )
when it is /fa , we must use bootstrap which is Rtl (Right to left)
Solution 
put this style sheet in case of using RTL
html[dir="rtl"] .row > .col-xs-1, html[dir="rtl"] .row > .col-xs-2, html[dir="rtl"] .row > .col-xs-3, html[dir="rtl"] .row > .col-xs-4, html[dir="rtl"] .row > .col-xs-5, html[dir="rtl"] .row > .col-xs-6, html[dir="rtl"] .row > .col-xs-7, html[dir="rtl"] .row > .col-xs-8, html[dir="rtl"] .row > .col-xs-9, html[dir="rtl"] .row > .col-xs-10, html[dir="rtl"] .row > .col-xs-11, html[dir="rtl"] .row > .col-xs-12 {
  float: right;
}
@media (min-width: 768px) {
  html[dir="rtl"] .row > .col-sm-1, html[dir="rtl"] .row > .col-sm-2, html[dir="rtl"] .row > .col-sm-3, html[dir="rtl"] .row > .col-sm-4, html[dir="rtl"] .row > .col-sm-5, html[dir="rtl"] .row > .col-sm-6, html[dir="rtl"] .row > .col-sm-7, html[dir="rtl"] .row > .col-sm-8, html[dir="rtl"] .row > .col-sm-9, html[dir="rtl"] .row > .col-sm-10, html[dir="rtl"] .row > .col-sm-11, html[dir="rtl"] .row > .col-sm-12 {
    float: right;
  }
}
@media (min-width: 992px) {
  html[dir="rtl"] .row > .col-md-1, html[dir="rtl"] .row > .col-md-2, html[dir="rtl"] .row > .col-md-3, html[dir="rtl"] .row > .col-md-4, html[dir="rtl"] .row > .col-md-5, html[dir="rtl"] .row > .col-md-6, html[dir="rtl"] .row > .col-md-7, html[dir="rtl"] .row > .col-md-8, html[dir="rtl"] .row > .col-md-9, html[dir="rtl"] .row > .col-md-10, html[dir="rtl"] .row > .col-md-11, html[dir="rtl"] .row > .col-md-12 {
    float: right;
  }
}
@media (min-width: 1170px) {
  html[dir="rtl"] .row > .col-lg-1, html[dir="rtl"] .row > .col-lg-2, html[dir="rtl"] .row > .col-lg-3, html[dir="rtl"] .row > .col-lg-4, html[dir="rtl"] .row > .col-lg-5, html[dir="rtl"] .row > .col-lg-6, html[dir="rtl"] .row > .col-lg-7, html[dir="rtl"] .row > .col-lg-8, html[dir="rtl"] .row > .col-lg-9, html[dir="rtl"] .row > .col-lg-10, html[dir="rtl"] .row > .col-lg-11, html[dir="rtl"] .row > .col-lg-12 {
    float: right;
  } 
 from the other hand  pull-right and pull-left for RTL languages

You can override .pull-right class to float to the left when it appears after an rtl element.
Like this:
.rtl {
    direction: RTL;
}
.rtl .pull-right {
    float:left !important;
}
And your div element:
id="div2" class="alert alert-info rtl"> هذا هو بلدي وصف الهوى class="badge badge-info">122 class="btn btn-lg pull-right" style="padding:0;" data-toggle="collapse" data-target="#aaa"> class="glyphicon glyphicon-chevron-down twitp_toggleable_chevron">
Here is a FIDDLE
Alternatively, you can do it using javascript: (Using your same code just add javascript)
$(document).ready(function() {
    $('.pull-right').each(function() {
        if($(this).parent().css('direction') == 'rtl')
            $(this).attr('style', 'float:left !important');
    });
});