begin process at 2012 05 27 05:53:13
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Fichiers/Disque

 > ASP.NET - AFFICHER LES DÉTAILS DE LA LISTE DES PARTITIONS DU SERVEUR WEB

ASP.NET - AFFICHER LES DÉTAILS DE LA LISTE DES PARTITIONS DU SERVEUR WEB


 Information sur la source

Note :
Aucune note
Catégorie :Fichiers/Disque Source .NET ( DotNet ) Niveau :Initié Date de création :13/09/2003 Date de mise à jour :13/09/2003 12:37:10 Vu :8 844

Auteur : fabrice69

Ecrire un message privé
Site perso
Ce membre participe au partage de revenus publicitaires
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note


 Description

Dans le cadre du développement d'un module de contrôle de serveur, un outil pour avoir la liste des partitions du serveur WEB et des Occupations de celui-ci.
Dans cet objectif, j'ai utilisé la possibilité d'intégrer les Objets classiques ASP3 :
- le Server.CreateObject("Scripting.FileSystemObject")

Ainsi en reprenant et adaptant du code pour l'ASP, j'ai fait fonctionner mon outil (je l'accorde ce n'est sans doute pas le plus propre, mais au moins il fait ce que je veux :) ).

Je vous fourni donc la source de cette page, il s'agit d'un User Control avec Code Behind (xxx.ascx + xxx.ascx.vb).

Source

  • ' ------ Page xxx.ASCX ------------
  • <%@ Control Language="vb" AutoEventWireup="false" Codebehind="xxx.ascx.vb" Inherits="MonProjet.DisquesControl" TargetSchema="http://schemas.microsoft.com/intellisense/ie3-2nav3-0" %>
  • <table class="box">
  • <tr class="boxheader">
  • <td class="boxheader">Systèmes de fichiers du Serveur</td>
  • </tr>
  • <tr class="boxbody">
  • <td><table width="100%" id="TableauDisque" align="center" runat="server">
  • <tr>
  • <td align="left" valign="top"><font size="-1"><b>Lettre</b></font></td>
  • <td align="left" valign="top"><font size="-1"><b>Chemin</b></font></td>
  • <td align="left" valign="top"><font size="-1"><b>Type</b></font></td>
  • <td align="left" valign="top"><font size="-1"><b>Utilisation</b></font></td>
  • <td align="right" valign="top"><font size="-1"><b>Libre</b></font></td>
  • <td align="right" valign="top"><font size="-1"><b>Utililisé</b></font></td>
  • <td align="right" valign="top"><font size="-1"><b>Taille</b></font></td>
  • </tr>
  • </table>
  • </td>
  • </tr>
  • </table>
  • ' ----------------------------------------
  • ' ------ Page xxx.ASCX.VB ------------
  • Imports System.Web.UI.HtmlControls
  • Public MustInherit Class DisquesControl
  • Inherits System.Web.UI.UserControl
  • Protected WithEvents TableauDisque As System.Web.UI.HtmlControls.HtmlTable
  • #Region " Code généré par le Concepteur Web Form "
  • 'Cet appel est requis par le Concepteur Web Form.
  • <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  • End Sub
  • Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
  • 'CODEGEN : cet appel de méthode est requis par le Concepteur Web Form
  • 'Ne le modifiez pas en utilisant l'éditeur de code.
  • InitializeComponent()
  • End Sub
  • #End Region
  • ' -----------------------------------------------------
  • Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  • Dim fso = Server.CreateObject("Scripting.FileSystemObject")
  • Dim drives = fso.Drives
  • Dim Drive
  • Dim isReady
  • Dim TotalDisqueLibre As Double = 0
  • Dim TotalDisque As Double = 0
  • For Each Drive In drives
  • Dim MaLigne As New HtmlControls.HtmlTableRow()
  • isReady = Drive.IsReady
  • If isReady Then
  • Dim Prop As Integer = CalculProportion(Drive.FreeSpace, Drive.TotalSize)
  • TotalDisque += Drive.TotalSize
  • TotalDisqueLibre += Drive.FreeSpace
  • AddCell(MaLigne, Drive.DriveLetter, "left")
  • AddCell(MaLigne, "[" & Drive.Path & "] (" & Drive.VolumeName & ")", "left")
  • AddCell(MaLigne, Drive.FileSystem, "left")
  • AddCell(MaLigne, RenvoiCodeImage(Prop), "left")
  • AddCell(MaLigne, Fonctions.AfficheTaille(Drive.FreeSpace, "o"), "right")
  • AddCell(MaLigne, Fonctions.AfficheTaille((Drive.TotalSize - Drive.FreeSpace), "o"), "right")
  • AddCell(MaLigne, Fonctions.AfficheTaille(Drive.TotalSize, "o"), "right")
  • Else
  • AddCell(MaLigne, Drive.DriveLetter, "left")
  • AddCell(MaLigne, "[" & Drive.Path & "]", "left")
  • AddCell(MaLigne, "", "left")
  • AddCell(MaLigne, "<i>Pas d'informations disponibles pour ce Lecteur</i>", "left", 4)
  • End If
  • TableauDisque.Rows.Add(MaLigne)
  • Next
  • Dim PropTotal As Integer = CalculProportion(TotalDisqueLibre, TotalDisque)
  • Dim MaLigneTotal As New HtmlControls.HtmlTableRow()
  • AddCell(MaLigneTotal, "<i>Totaux :&nbsp;&nbsp;</i>", "right", 3)
  • AddCell(MaLigneTotal, RenvoiCodeImage(PropTotal), "left")
  • AddCell(MaLigneTotal, Fonctions.AfficheTaille(TotalDisqueLibre, "o"), "right")
  • AddCell(MaLigneTotal, Fonctions.AfficheTaille((TotalDisque - TotalDisqueLibre), "o"), "right")
  • AddCell(MaLigneTotal, Fonctions.AfficheTaille(TotalDisque, "o"), "right")
  • TableauDisque.Rows.Add(MaLigneTotal)
  • End Sub
  • ' -----------------------------------------------------
  • Private Sub AddCell(ByVal tr As HtmlTableRow, ByVal sM As String, ByVal Alignement As String, Optional ByVal ColSpan As Integer = 0)
  • 'Ajoute une cellule dans la ligne du tableau
  • Dim td As New HtmlTableCell()
  • td.Align = Alignement
  • td.VAlign = "top"
  • If ColSpan > 0 Then
  • td.ColSpan = ColSpan
  • End If
  • td.InnerHtml = "<font size='-1'>" & sM & "</font>"
  • tr.Cells.Add(td)
  • End Sub
  • ' -----------------------------------------------------
  • Private Function CalculProportion(ByVal TailleLibre As Double, ByVal TailleTotale As Double) As Integer
  • Return Int(((TailleTotale - TailleLibre) / TailleTotale) * 100)
  • End Function
  • ' -----------------------------------------------------
  • Private Function RenvoiCodeImage(ByVal Taille As Integer) As String
  • Dim couleur As String = ""
  • Dim Retour As String = ""
  • If Taille > 95 Then couleur = "red"
  • Retour = "<img height='10' src='./images/" & couleur & "bar_left.gif'>"
  • Retour &= "<img src='./images/" & couleur & "bar_middle.gif' height='10' width='"
  • Retour &= (Taille * 2) & "'><img height='10' src='./images/" & couleur & "bar_right.gif'>&nbsp;" & Taille & "%"
  • Return Retour
  • End Function
  • ' -----------------------------------------------------
  • End Class
  • ' -----------------------------------------------------
' ------ Page xxx.ASCX ------------

<%@ Control Language="vb" AutoEventWireup="false" Codebehind="xxx.ascx.vb" Inherits="MonProjet.DisquesControl" TargetSchema="http://schemas.microsoft.com/intellisense/ie3-2nav3-0" %>
<table class="box">
 <tr class="boxheader">
  <td class="boxheader">Systèmes de fichiers du Serveur</td>
 </tr>
 <tr class="boxbody">
  <td><table width="100%" id="TableauDisque" align="center" runat="server">
    <tr>
      <td align="left" valign="top"><font size="-1"><b>Lettre</b></font></td>
      <td align="left" valign="top"><font size="-1"><b>Chemin</b></font></td>
      <td align="left" valign="top"><font size="-1"><b>Type</b></font></td>
      <td align="left" valign="top"><font size="-1"><b>Utilisation</b></font></td>
      <td align="right" valign="top"><font size="-1"><b>Libre</b></font></td>
      <td align="right" valign="top"><font size="-1"><b>Utililisé</b></font></td>
      <td align="right" valign="top"><font size="-1"><b>Taille</b></font></td>
     </tr>
    </table>
   </td>
 </tr>
</table>

' ----------------------------------------
' ------ Page xxx.ASCX.VB ------------

Imports System.Web.UI.HtmlControls

Public MustInherit Class DisquesControl
    Inherits System.Web.UI.UserControl
    Protected WithEvents TableauDisque As System.Web.UI.HtmlControls.HtmlTable


#Region " Code généré par le Concepteur Web Form "

    'Cet appel est requis par le Concepteur Web Form.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN : cet appel de méthode est requis par le Concepteur Web Form
        'Ne le modifiez pas en utilisant l'éditeur de code.
        InitializeComponent()
    End Sub

#End Region

    ' -----------------------------------------------------
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim fso = Server.CreateObject("Scripting.FileSystemObject")
        Dim drives = fso.Drives
        Dim Drive
        Dim isReady

        Dim TotalDisqueLibre As Double = 0
        Dim TotalDisque As Double = 0

        For Each Drive In drives
            Dim MaLigne As New HtmlControls.HtmlTableRow()
            isReady = Drive.IsReady
            If isReady Then
                Dim Prop As Integer = CalculProportion(Drive.FreeSpace, Drive.TotalSize)
                TotalDisque += Drive.TotalSize
                TotalDisqueLibre += Drive.FreeSpace

                AddCell(MaLigne, Drive.DriveLetter, "left")
                AddCell(MaLigne, "[" & Drive.Path & "] (" & Drive.VolumeName & ")", "left")
                AddCell(MaLigne, Drive.FileSystem, "left")
                AddCell(MaLigne, RenvoiCodeImage(Prop), "left")
                AddCell(MaLigne, Fonctions.AfficheTaille(Drive.FreeSpace, "o"), "right")
                AddCell(MaLigne, Fonctions.AfficheTaille((Drive.TotalSize - Drive.FreeSpace), "o"), "right")
                AddCell(MaLigne, Fonctions.AfficheTaille(Drive.TotalSize, "o"), "right")

            Else
                AddCell(MaLigne, Drive.DriveLetter, "left")
                AddCell(MaLigne, "[" & Drive.Path & "]", "left")
                AddCell(MaLigne, "", "left")
                AddCell(MaLigne, "<i>Pas d'informations disponibles pour ce Lecteur</i>", "left", 4)
            End If
            TableauDisque.Rows.Add(MaLigne)
        Next

        Dim PropTotal As Integer = CalculProportion(TotalDisqueLibre, TotalDisque)
        Dim MaLigneTotal As New HtmlControls.HtmlTableRow()

        AddCell(MaLigneTotal, "<i>Totaux :&nbsp;&nbsp;</i>", "right", 3)
        AddCell(MaLigneTotal, RenvoiCodeImage(PropTotal), "left")
        AddCell(MaLigneTotal, Fonctions.AfficheTaille(TotalDisqueLibre, "o"), "right")
        AddCell(MaLigneTotal, Fonctions.AfficheTaille((TotalDisque - TotalDisqueLibre), "o"), "right")
        AddCell(MaLigneTotal, Fonctions.AfficheTaille(TotalDisque, "o"), "right")

        TableauDisque.Rows.Add(MaLigneTotal)

    End Sub

    ' -----------------------------------------------------
    Private Sub AddCell(ByVal tr As HtmlTableRow, ByVal sM As String, ByVal Alignement As String, Optional ByVal ColSpan As Integer = 0)
        'Ajoute une cellule dans la ligne du tableau
        Dim td As New HtmlTableCell()
        td.Align = Alignement
        td.VAlign = "top"
        If ColSpan > 0 Then
            td.ColSpan = ColSpan
        End If
        td.InnerHtml = "<font size='-1'>" & sM & "</font>"
        tr.Cells.Add(td)
    End Sub

    ' -----------------------------------------------------
    Private Function CalculProportion(ByVal TailleLibre As Double, ByVal TailleTotale As Double) As Integer

        Return Int(((TailleTotale - TailleLibre) / TailleTotale) * 100)
    End Function

    ' -----------------------------------------------------
    Private Function RenvoiCodeImage(ByVal Taille As Integer) As String

        Dim couleur As String = ""
        Dim Retour As String = ""
        If Taille > 95 Then couleur = "red"

        Retour = "<img height='10' src='./images/" & couleur & "bar_left.gif'>"
        Retour &= "<img src='./images/" & couleur & "bar_middle.gif' height='10' width='"
        Retour &= (Taille * 2) & "'><img height='10' src='./images/" & couleur & "bar_right.gif'>&nbsp;" & Taille & "%"
        Return Retour
    End Function

    ' -----------------------------------------------------

End Class

' -----------------------------------------------------
 

 Conclusion

Ce User Control fera parti d'un projet plus conséquent en cours de développement qui sera livré bientot ici.

Bon Coding

Romelard Fabrice (Alias F___)


 Sources du même auteur

Source .NET (Dotnet) SHAREPOINT 2007 - OBTENIR LA LISTE DES WEBPARTS DANS UNE PAG...
Source .NET (Dotnet) SHAREPOINT 2007 - OBTERNIR LA LISTE DES FEATURES D'UN SITE
Source avec une capture Source .NET (Dotnet) SHAREPOINT 2007 - CHARGER LA LISTE DES COLLATIONS SHAREPOINT...
Source avec une capture Source .NET (Dotnet) SHAREPOINT 2007 - CHARGER LA LISTE DES LANGUES INSTALLÉES DA...
Source .NET (Dotnet) C# - FONCTION TRÈS SIMPLE POUR ENVOYER UN MAIL VIA SMTP

 Sources de la même categorie

Source .NET (Dotnet) IMPORTER UN FICHIER EXCEL DEPUIS UN POSTE ET L'AJOUTER SUR L... par jseblavoie
SERVER.MAPPATH QUI ACCEPTE LES ../ par divlys
UPLOAD D'IMAGES VIA ADODB.STREAM ET SQL SERVER par Nicolas_kojack
LISTING DE FICHIERS ET RÉPERTOIRES (FONCTION RÉCURSIVE) par Warwick
Source avec Zip UTILITAIRE POUR FORCER LE TÉLÉCHARGEMENT D'UN FICHIER SUR UN... par shaiulud

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,796 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales