D
Dave
Hello. I need to load an URL and save it to a file in Asp.Net. The
function below is creating the file, but isn't putting the data in it.
Also the data is binary, so I'm not sure if I need to fiddle with
encoding or whatnot.
Dave
Private Function GetURLSave(ByVal sURL As String,ByVal sFileName As
String) As Boolean
Dim oRequest As System.Net.HttpWebRequest =
System.Net.HttpWebRequest.Create(sURL)
oRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR
1.2.30703)"
Dim oResponse As System.Net.WebResponse =
oRequest.GetResponse()
Dim oReader As System.IO.StreamReader = New
System.IO.StreamReader(oResponse.GetResponseStream)
Try
Dim oFile As System.IO.FileStream = New _
System.IO.FileStream(sFileName,
System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite,
System.IO.FileShare.None)
Dim oWriter As New System.IO.StreamWriter(oFile)
Dim sText As String = oReader.ReadToEnd
oWriter.Write(sText)
oWriter.Flush()
oWriter.Close()
oFile.Close()
Catch ex As Exception
GetURLSave = False
Finally
GetURLSave = True
End Try
oReader.Close()
oResponse.Close()
End Function
function below is creating the file, but isn't putting the data in it.
Also the data is binary, so I'm not sure if I need to fiddle with
encoding or whatnot.
Dave
Private Function GetURLSave(ByVal sURL As String,ByVal sFileName As
String) As Boolean
Dim oRequest As System.Net.HttpWebRequest =
System.Net.HttpWebRequest.Create(sURL)
oRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR
1.2.30703)"
Dim oResponse As System.Net.WebResponse =
oRequest.GetResponse()
Dim oReader As System.IO.StreamReader = New
System.IO.StreamReader(oResponse.GetResponseStream)
Try
Dim oFile As System.IO.FileStream = New _
System.IO.FileStream(sFileName,
System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite,
System.IO.FileShare.None)
Dim oWriter As New System.IO.StreamWriter(oFile)
Dim sText As String = oReader.ReadToEnd
oWriter.Write(sText)
oWriter.Flush()
oWriter.Close()
oFile.Close()
Catch ex As Exception
GetURLSave = False
Finally
GetURLSave = True
End Try
oReader.Close()
oResponse.Close()
End Function