Hej,
Her er min kode:
[code]
Public Class FileUpload
Private Const BOUNDARY As String = "MichaelMichael"
Delegate Sub SetTextCallback()
'Public Shared Sub Main(ByVal args As String())
' upload("
http://localhost/upload.php", "C:\z.zip")
' End Sub
Public Shared Sub upload()
Dim url As String = "
http://fakeachievement.com/upload.pl" Dim binfile As String = "C:\test.txt"
Dim Myfilesize As Integer = FileHand.GetFileSize(binfile)
Dim myprogress As Integer = 0
Dim MyFileLink As String = ""
Console.WriteLine("Uploading: " + Path.GetFileName(binfile))
Dim req As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
req.Method = "POST"
req.ContentType = "multipart/form-data, boundary=" & BOUNDARY
Dim post As New StreamWriter(req.GetRequestStream())
post.WriteLine("--" & BOUNDARY)
post.WriteLine("Content-disposition: form-data; name=""filename""; filename=""" & Path.GetFileName(binfile) & """")
post.WriteLine("Content-type: application/octet-stream")
post.WriteLine("Content-Length: " & (New FileInfo(binfile)).Length)
post.WriteLine("Content-Transfer-Encoding: binary")
post.WriteLine("")
post.Flush()
Dim binf As New FileStream(binfile, FileMode.Open)
Dim b(10000) As Byte
Dim n As Integer
Dim sofar As Integer = 0
n = binf.Read(b, 0, b.Length)
Console.WriteLine("File size: " & Myfilesize / 1024 / 1024 & " megabytes")
While n > 0
post.BaseStream.Write(b, 0, n)
sofar += n
'Console.WriteLine(sofar & " - " & Myfilesize)
myprogress = ((sofar / Myfilesize) * 100)
'Console.WriteLine(myprogress)
n = binf.Read(b, 0, b.Length)
End While
binf.Close()
post.BaseStream.Flush()
post.WriteLine()
post.WriteLine("--" & BOUNDARY & "--")
post.Close()
Dim resp As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)
Dim sr As StreamReader = New StreamReader(resp.GetResponseStream())
Dim fullresp As String = sr.ReadToEnd()
MyFileLink = Trim(Replace(fullresp, Right(fullresp, 20), ""))
Console.WriteLine(MyFileLink)
######HER VIL JEG GERNE SKRIVE TIL FORMEN#######
Form1.lblLink.Text = MyFileLink
sr.Close()
Console.WriteLine("Response was: " & resp.StatusCode & " - " & resp.StatusDescription)
If resp.StatusDescription = "OK" Then Console.WriteLine("Success!")
resp.Close()
Console.Read()
Form1.myUploadProgress.Value = 0
End Sub
End Class
[/code]