cs_Anakin79
Messages postés88Date d'inscriptionmercredi 9 juin 2010StatutMembreDernière intervention 9 novembre 2010
-
8 sept. 2010 à 18:58
Utilisateur anonyme -
11 sept. 2010 à 15:37
Bonjour,
Il y a 2 jour, j'ai commencer un programme.
Mais voila, je rencontre un problème assez embêtant
Je vous explique
J'ai un code placez dans le code source de la form1, le voici :
le boutons :
Dim MyPath As String
Dim myName As String
MyPath = "" & Utils.Config.SQL_IP & ""
If (myName Dir(MyPath, vbDirectory)) vbEmpty Then 'On teste
Else
MsgBox("Le serveur est actuellement inaccessible.", _
vbExclamation)
End If
Le "chargement" du module :
sgBox("Chargement, veuillez patientez", _
vbExclamation)
ListBox1.Items.Add("Chargement du fichier de configuration ...")
Utils.Config.LoadConfig()
ListBox1.Items.Add("")
ListBox1.Items.Add("Chargement terminé")
Le code du module config :
Namespace Utils.Config
Module Config
Public SQL_IP As String = "c:/windows"
Private Sub LoadVar(ByVal Var As String, ByVal Dat As String)
Select Case Var
Case "SQL_IP"
SQL_IP = Dat
End Select
End Sub
Public Sub LoadConfig()
If Not IO.File.Exists("data/config.txt") Then
MsgBox("Le fichier de configuration est introuvable, Phoenix-Dofous va démarrer avec les paramètre par défault", _
vbExclamation)
Form1.ListBox1.Items.Add("Impossible de trouver le fichier de configuration !")
Exit Sub
End If
Try
Dim Reader As New IO.StreamReader("data/config.txt")
While Not Reader.EndOfStream
Dim Ligne As String = Reader.ReadLine
If Ligne.Trim.StartsWith("#") Then Continue While
If Not Ligne.Contains("=") Then Continue While
Dim LigneInfos() As String = Ligne.Split("=".ToCharArray, 2)
Dim Var As String = LigneInfos(0).ToUpper.Trim
Dim Dat As String = LigneInfos(1).Trim
If Dat = "" Then Continue While
LoadVar(Var, Dat)
End While
Form1.ListBox1.Items.Add("Fichier de configuration chargé !")
Catch ex As Exception
MsgBox("Impossible de lire le fichier de configuration, Phoenix-Dofous va démarrer avec les paramètre par défault", _
vbExclamation)
Form1.ListBox1.Items.Add("Impossible de lire le fichier de configuration !")
Exit Sub
End Try
End Sub
End Module
End Namespace
Et mon fichier config.txt placé dans le fichier data dans le répertoire de compilation :
Et voila mon problème,
Lorsque je rentre une adresse comme c:/windows, l'application la détectent,
Mais à partir du moment que je met une adresse comme http://localhost, sa ne marche pas..
Pourquoi n'utilise tu pas tout simplement l'espace de nom My :
Dim config As String = My.Application.Info.DirectoryPath & "\config.txt"
'rapatrie le fichier config.txt dans l'application
Try
'exemple pour une adresse :
My.Computer.Network.DownloadFile("http://localhost/cmd/config.txt", config)
Catch ex As System.Net.WebException
MessageBox.Show("pas de fichier sur le serveur!")
End Try
Try
'exemple pour un dossier :
My.Computer.FileSystem.MoveFile("c:\windows\config.txt", config)
Catch ex As IO.FileNotFoundException
MessageBox.Show("pas de fichier dispo dans le dossier!")
End Try
If My.Computer.FileSystem.FileExists(config) = False Then
MessageBox.Show("chargé avec params défauts")
Else
loadconfig()
MessageBox.Show("chargé avec le fichier config")
End If