C# / VB .NET – Upload de fichiers par webservice

Méthode du WebService :


public void UploadFile(byte[] f, string fileName)




MemoryStream ms = new MemoryStream(f);

FileStream fs = new FileStream(@”C:\transfert\” + fileName, FileMode.Create);


ms.Close(); fs.Close();




catch (Exception ex)


return ex.Message.ToString();




Appel du webservice en VB.NET :

Sub envoie(cheminEntier As String)


Dim svr As New ServiceReference1.svTransfertSoapClient()

Dim strFile As String = System.IO.Path.GetFileName(cheminEntier)

Dim fInfo As FileInfo = New FileInfo(cheminEntier)

Dim numBytes As Long = fInfo.Length

Dim dLen As Double = Convert.ToDouble(fInfo.Length / 1000000)

If dLen < 4 Then

Dim fStream As FileStream = New FileStream(cheminEntier, FileMode.Open, FileAccess.Read)

Dim br As BinaryReader = New BinaryReader(fStream)

Dim data As Byte() = br.ReadBytes(CInt(numBytes))


Dim sTmp As String = svr.UploadFile(data, strFile)



End If

Catch ex As Exception

My.Computer.FileSystem.WriteAllText(“C:\\test1\\log.txt”, ex.Message, True)

End Try

End Sub



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s