Upload Fichier Via WebServer

cs_simoneo Messages postés 20 Date d'inscription samedi 4 novembre 2006 Statut Membre Dernière intervention 29 juin 2008 - 22 juin 2008 à 03:58
cs_simoneo Messages postés 20 Date d'inscription samedi 4 novembre 2006 Statut Membre Dernière intervention 29 juin 2008 - 22 juin 2008 à 15:39
Salut.
Je voudrais créer une application winforms pour télécharger des fichiers vers mon ordinateur. Pour cela j'ai créer un service web nommé uploadFileManager dont le code est:

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.IO

<WebService(Namespace:="http://theone.servehttp.com/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class uploadFileManager
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Sub upload(ByVal Filename As String, ByVal oFileByte As Byte())
        File.WriteAllBytes("c:" & Filename, oFileByte)
    End Sub

End Class

J'ai placé mon service web dans le serveur IIS 5.1 sur mon windows XP SP2.  Puis j'ai créé une application winforms à l'aide de VS2005 puis j'ai ajouter un référence web nommée srv vers mon service web sur localhost. L'application contient seulement un bouton dont le code est:

Dim ch As String
        Dim oFileByte As Byte()
        Me.OpenFileDialog1.ShowDialog()
        ch = Me.OpenFileDialog1.FileName
        If ch = ""Then Exit Sub
        Me.TextBox1.Text = ch
        oFileByte = IO.File.ReadAllBytes(ch)
        Dim fi As New IO.FileInfo(ch)
        Dim fm As New srv.uploadFileManager
        Try
            fm.upload(fi.Name, oFileByte)
        Catch ex As Exception
            Me.RichTextBox1.Text = ex.Message
        End Try

Quand je veux uploader un fichier 't.txt' qui existe dans le même ordinateur que le service web et l'application, je reçois le message d'erreur suivant:

System.Web.Services.Protocols.SoapException: Le serveur n'a pas pu traiter la demande. ---> System.UnauthorizedAccessException: L'accès au chemin d'accès 'c:\t.txt' est refusé.
   à System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   à System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
   à System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   à System.IO.File.WriteAllBytes(String path, Byte[] bytes)
   à uploadFileManager.upload(String Filename, Byte[] oFileByte)
   --- Fin de la trace de la pile d'exception interne ---

Veuillez m'aider. Merci d'avance.

1 réponse

cs_simoneo Messages postés 20 Date d'inscription samedi 4 novembre 2006 Statut Membre Dernière intervention 29 juin 2008
22 juin 2008 à 15:39
Quand je remplace "c:" par "d:" ou bien "d:\rep"  ça marche très bien meme quand j'utilise server.mapPath(".")
0
Rejoignez-nous