We help IT Professionals succeed at work.

Uplolad file via System.Net.HttpWebRequest

Shezad Ahmed
Shezad Ahmed asked
on
High Priority
57 Views
Last Modified: 2020-02-28
I am trying to upload a file using HttpWebRequest.

The file does not seem to get uploaded.

I don't get any errors.

  Try


            Dim FTPaddress As String = "https://<server>/test/Khaosrs.exe/soap/IKosWeb/" + FileInfo.Name

            Dim request As System.Net.HttpWebRequest = DirectCast(System.Net.WebRequest.Create(FTPaddress), System.Net.HttpWebRequest)
            request.Method = System.Net.WebRequestMethods.Ftp.UploadFile

            Dim file() As Byte = System.IO.File.ReadAllBytes(Filelocation)

            Dim strz As System.IO.Stream = request.GetRequestStream()
            strz.Write(file, 0, file.Length)
            strz.Close()
            strz.Dispose()

        Catch ex As Exception
            WritetoEventViewer("CPS - SL Update - UploadFiletoKhaosFTPsite() - " + ex.Message, True)
        End Try
Comment
Watch Question

Senior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016
Commented:
I prefer to use FTP when I have to transfer files but once that said, have a look at https://www.dreamincode.net/forums/topic/249603-upload-file-whit-httprequest/