vendredi 15 février 2013

Windows 8 : Open a local file and read Xml content

Thanks to this tutorial you will learn how to open an Xml File located in you Solution Explorer and how to retrieve value.

We will use Linq on Xml file so you have to add the following  librairies to your projet :


using System.Xml.Linq;
using Windows.Data.Xml.Dom;
using Windows.Storage;


Add a folder named 'Data' for exemple into you Windows Store solution and add the following Xml content into the file 'Schools.xml':

<?xml version="1.0" encoding="utf-8" ?>
<school>
  <name>IUT Toulouse</name>
  <type>Public</type>
  <location>
    <X>45.1</X>
    <Y>32.5</Y>
  </location>
</school>

And into a EventHandler or in the Page_Load for example add the folowing code :

Windows.Storage.StorageFolder storageFolder =await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Data"); StorageFile storageFile =await storageFolder.GetFileAsync("Schools.xml"); IAsyncOperation<IRandomAccessStream> stream = await storageFile.OpenAsync(FileAccessMode.Read); XmlDocument xmlDoc = await XmlDocument.LoadFromFileAsync(storageFile); XDocument doc = XDocument.Parse(xmlDoc.GetXml()); string name = from schools in doc.Descendants("name") select schools.Value;string type = from schools in doc.Descendants("type") select schools.Value;

At the end of the code the variables  name and type contains the value retrieve in the xml file.





jeudi 7 février 2013

Windows 8 par où commencer ?

Voici quelques liens qui peuvent vous aidez à prendre en main windows 8 aussi bien niveau usage que développement :


Le top 10 des App :
http://www.pcworld.com/article/2012988/10-windows-8-apps-you-should-download-first.html


Génération App Microsoft avec les offres en cours et les concours:
http://www.generationapp.com/code/#fbid=FcBScBurfJr


Vos ressources de développement avec Microsoft code pour windowsApp:
http://code.msdn.microsoft.com/windowsapps

Comment concevoir vos applications et les rendre #1:
http://msdn.microsoft.com/library/windows/apps/hh779072/


Utilisation de la barre d'application suivant le context:
http://blogs.msdn.com/b/windowsappdev/archive/2012/09/06/embracing-ui-on-demand-with-the-app-bar.aspx

mercredi 30 janvier 2013

How to log directly into EventLog server (Observateurs d'événements)

Every application can write into the server event log diary thanks to a C# class called "System.Diagnostics.EventLog"

In order to log message you have to instanciate one object of this class and specify two important elements Source and Log

Log will define the category in which your message will appear, you can use 'Application' 'Security' 'Installation' and so on.

Source define the name of the application that log the message, you can use your application name for example.


And the C# code to log into the diary event :


private static string SourceLog = "MyApplicationName";
private static string LogApp = "Application";
private static System.Diagnostics.EventLog eventLogApplication;

/// <summary>
/// Log the message into the Windows event log diary
/// </summary>
/// <param name="message">Message</param>
static void Log( string message )
{
     Log( message, System.Diagnostics.EventLogEntryType.Information );
}

/// <summary>
/// Log the message into the Windows event log diary
/// </summary>
/// <param name="message">Message enregistré</param>
/// /// <param name="entryType">Entry type</param>
static void Log( string message, System.Diagnostics.EventLogEntryType entryType )
{
     try
     {
          //Initialisation
          if (!System.Diagnostics.EventLog.SourceExists(SourceLog))
         {
              System.Diagnostics.EventLog.CreateEventSource(SourceLog, LogApp);
         }
         if (eventLogApplication == null)
        {
             eventLogApplication = new System.Diagnostics.EventLog();
             ((System.ComponentModel.ISupportInitialize)(eventLogApplication)).BeginInit();
             eventLogApplication.Source = SourceLog;
              eventLogApplication.Log = LogApp;
        }

        //Writing
        eventLogApplication.WriteEntry(message, entryType);
   }
    catch (Exception e)
    {
        Log("Error Log : " + e.InnerException + " " + e.Message, EventLogEntryType.Error);
      }
}

lundi 28 janvier 2013

BeMyApp dev kings 2013

L'initiative BeMyApp continue son petit bonhomme de chemin et propose un nouveau défi pour les fan de développement :

http://pitchyourapp.eventbrite.fr/

Source : BeMyApp.fr

DEV KINGS 2013 - On remet ça !
Edition spéciale app'citoyenne

Venez développer vos applications citoyennes et participez au concours des DEV KINGS 2013.
Choisissez la localité à représenter, créez votre team et développez vos app' !


2 MOIS POUR DEVELOPPER LA MEILLEURE APP'CITOYENNE
Le 12 février
Soirée Pitch Your App, lancement du concours. Pitchez vos idées, rencontrez votre équipe de développeurs, porteurs d'idées, designers et autres super pouvoirs.

Du 12 février au 12 avril
Sessions de coaching Microsoft, développez à l'aide des experts Microsoft vos applications en deux mois.

Weekend du 12 au 14 avril
DEV KINGS 2013inscrivez-vous et venez terminer vos applications avec vos équipes en 48h ! Participez à la grande finale, soumettez vos applications sur Windows Store et passez un WeekEnd de folie dans l'Under d'EPITECH.


INSCRIVEZ-VOUS ICI A LA SOIREE PITCH YOUR APP
Mardi 12 février Chez Régine, venez créer votre équipe à la soirée Pitch Your App

Le but de cette soirée est de mettre en relation des personnes qui ont des idées d'applications, des développeurs et des designers pour créer des applications citoyennes sous Windows 8 et Windows Phone.
Vous avez une super idée d'application, mais pas les compétences, c'est le moment de vous inscrire pour la pitcher et trouver votre team. 
Vous êtes développeurs, designers ou avez des compétences à apporter ? Alors participez au challenge pour rejoindre une équipe, trouvez des compétences complémentaires pour vos applis et gagnez des dotations Microsoft et Intel !

SharePoint 2013 : Log as an other user, add the custom action

Please follow the following step in order to activate the option 'Log as an other user'.

Open the file located in


C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\Welcome.ascx

Add the following lines after the element « ID_RequestAccess » :

<SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser"
Text="<%$Resources:wss,personalactions_loginasdifferentuser%>"
 Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>"
 MenuGroupId="100"
 Sequence="100"
 UseShortId="true"
 />
















And save the file.

You can now do a 'iisreset' and see the result as :


http://support.microsoft.com/kb/2752600


jeudi 24 janvier 2013

Sort DataTable DataView ascending with null or empty last.


You first need to specify the sorting column in 'param' and replace the original DataTable by 'collection'.

In this example I filter a DataTable with the SelectedValue given by my DropDownList control (ddlFiltre).

In the DataRow array 'nameNotNull' I simply simply the data that are not null for my parameter and sort them.
And in the DataRow array 'nameNull' I select the null data for my parameter.

You just need to merge the two DataRow array and bind it with the GridView

DataTable collection;
//Fill the dataTable
//...
///

protected void ddlFiltre_Change(object sender, EventArgs e){ 
  if (!string.IsNullOrEmpty(ddlFiltre.SelectedValue)) {   
       string param = "Name";
       DataRow[] nameNotNull = collection.Select(string.Format("{0} IS NOT NULL AND {0} <> ''", param),string.Format("{0} ASC", param));
       DataRow[] nameNull = collection.Select(string.Format("{0} IS NULL OR {0} = ''", param));
        DataTable collectionSorted = collection.Clone();
   if (nameNotNull.Length > 0)
   {
      foreach (DataRow dr in nameNotNull)
      {
         DataRow newRow = collectionSorted.NewRow();
         newRow.ItemArray = dr.ItemArray;
         collectionSorted.Rows.Add(newRow);
      }
      if (nameNull.Length > 0)
      {
         foreach (DataRow dr in nameNull)
         {
            DataRow newRow = collectionSorted.NewRow();
            newRow.ItemArray = dr.ItemArray;
            collectionSorted.Rows.Add(newRow);
         }
       }
    }
    else if (nameNull.Length > 0)
    {
       foreach (DataRow dr in nameNull)
       {
          DataRow newRow = collectionSorted.NewRow();
          newRow.ItemArray = dr.ItemArray;
          collectionSorted.Rows.Add(newRow);
       }
    }
    gvItems.DataSource = collectionSorted;
    gvItems.DataBind();
}
}

jeudi 10 janvier 2013

Modifier les pages SharePoint par défaut. (AccessDenied.aspx, Confirmation.aspx, Error.aspx, Login.aspx, RequestAccess.aspx, Signout.aspx, WebDeleted.aspx)

Il est possible d'avoir de modifier l'url des pages suivantes et de les surcharger pour intégrer le design de l'entreprise :
  •  AccessDenied (Specifies AccessDenied.aspx)
  •  Confirmation (Specifies Confirmation.aspx)
  •  Error (Specifies Error.aspx)
  •  Login (Specifies Login.aspx)
  •  RequestAccess (Specifies ReqAcc.aspx)
  •  Signout (Specifies SignOut.aspx)
  •  WebDeleted (Specifies WebDeleted.aspx)
Avec les classes correspondantes se trouvant dans le namespace : 


Microsoft.SharePoint.ApplicationPages



Il est aussi nécéssaire de modifier la masterpage de votre page d'application par :

MasterPageFile="~/_layouts/simple.master"

Et d'hériter la classe correspondante 

UnsecuredLayoutsPageBase pour AccessDenied.aspx par exemple.




La modification de ces pages peut ensuite se faire de deux manières, soit par code C# :

SPWebApplication.UpdateMappedPage(SPWebApplication.SPCustomPage.AccessDenied, 

"_layouts/MyAccessDenied.aspx);


Soit via powershell : 


Set-SPCustomLayoutsPage -Identity "AccessDenied" -RelativePath 

"/_layouts/MyAccessDenied.aspx" -WebApplication http://serveur 

Get-SPCustomLayoutsPage –Identity "AccessDenied" -WebApplication http://serveur 

iisreset


Voici une page complète d'une customisation simple de la page AccessDenied.aspx avec changement du lien 'Retour au site' par défaut : 



<%@ Assembly Name="Name, Version=1.0.0.0, Culture=neutral,PublicKeyToken=092c1c010b5e2820" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AccessDenied.aspx.cs" Inherits="AccessDenied" MasterPageFile="~/_layouts/simple.master" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Import Namespace="Microsoft.SharePoint.Publishing" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="Microsoft.SharePoint.WebControls" %>

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (SPContext.Current != null && SPContext.Current.Web != null && SPContext.Current.Web.CurrentUser != null)
        {
            LabelUserName.Text = SPContext.Current.Web.CurrentUser.LoginName;
        }
     
        if (SPContext.Current != null && SPContext.Current.Web != null && SPContext.Current.Web.Site != null
            && SPContext.Current.Web.Site.WebApplication != null)
        {
         
            Page.ClientScript.RegisterStartupScript(this.GetType(), "click",
        "modifierRetour('" + SPContext.Current.Web.Site.WebApplication.Sites[0].Url + "');", true);
        }


   //     HLinkLoginAsAnother.Attributes.Add("onclick", "LoginAsAnother('\u002fsites\u002factuariat\u002f_layouts\u002fcloseConnection.aspx?loginasanotheruser=true', 1)");
    //    HLinkLoginAsAnother.NavigateUrl = "http://www.google.com/";
    }
    </script>

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
    <style type="text/css"></style>
    <script type="text/javascript">
        function modifierRetour() {
            var backbutton = document.getElementById('ctl00_PlaceHolderGoBackLink_idSimpleGoBackToHome');

            if (backbutton != null) {
                backbutton.href = "javascript:history.back()"; // cacherBackToSite.arguments[0];
            }
        }
</script>
</asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
 
   <table border="0" cellpadding="0">
         <asp:Panel id="PanelUserName" runat="server">
         <tr>
       <td class="ms-sectionheader">
       <%--<img src="/_layouts/images/ListSet.gif" alt="" />--%>
       <SharePoint:EncodedLiteral ID="EncodedLiteral3" runat="server" text="<%$Resources:wss,accessDenied_currentuser%>" EncodeMethod='HtmlEncode'/>
       </td>
         </tr>
         <tr>
       <td valign="top" class="ms-descriptiontext"><SharePoint:EncodedLiteral ID="EncodedLiteral4" runat="server" text="<%$Resources:wss,accessDenied_loggedInAs%>" EncodeMethod='HtmlEncode'/>
       &#160;<b><asp:Label id="LabelUserName" runat="server"/></b>
       </td>
         </tr>
         </asp:Panel>
    </table>
</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
 <SharePoint:EncodedLiteral ID="EncodedLiteral1" runat="server" text="Accès refusé au site demandé" EncodeMethod='HtmlEncode'/>
</asp:Content>

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
    <SharePoint:EncodedLiteral ID="EncodedLiteral2" runat="server" text="Vous n'avez pas le droit de visualiser ce site." EncodeMethod='HtmlEncode'/>
</asp:Content>