File Download - web service
-
I am trying to build a web service that downloads a file to my local directory. I have the basics here but I just cannot get it to work, anybody know of any examples on this. Here is my code so far.
Dim l_oWR As WebRequest Dim l_oWebResp As WebResponse Dim l_oBR As BinaryReader Dim l_oBW As BinaryWriter Dim l_oStream As Stream Dim bFile() As Byte Dim l_iCnt As Long Dim l_dtNow As DateTime = DateTime.Now Dim l_sDir As String = l_dtNow.ToString("MMddyyyy") Dim l_oDir As Directory Dim l_sFile As String Dim l_sCnnStr As String Try 'download file l_oWR = HttpWebRequest.Create("http://www.abc.com/abc.exe") l_oWebResp = l_oWR.GetResponse() l_oBR = New BinaryReader(l_oWebResp.GetResponseStream(), Encoding.ASCII) l_iCnt = l_oWebResp.ContentLength bFile = l_oBR.ReadBytes(CType(l_iCnt, Integer)) If Not System.IO.Directory.Exists("C:\ofac") Then System.IO.Directory.CreateDirectory("C:\ofac") End If l_oStream = New FileStream("C:\ofac\t11sdall.exe", FileMode.Create, FileAccess.Write) l_oBW = New BinaryWriter(l_oStream) l_oBW.Write(bFile)
Thanks for any help here! Jordan