Greetings:
I need to download an executable and some other binary files (a C++
DLL) from a virtual directory in my WinForms application. No-Touch
Deployment manages my .NET code fine but auxilliary files such as these
must be downloaded "manually" in my code. My text-based files download
fine but I've ran into a problem downloading an .EXE. When it
downloads the file size is the same but it has been altered somehow
because a) the icon doesn't display in Explorer (a generic icon is
used) and b) the program creates a fault when I double-click it. I've
used a diff analyzer to compare the two files and there are some places
in the downloaded file that are empty where there should be data. Here
is the code I am using:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.ContentType = @"application/octet-stream";
request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = null;
try
{
response = (HttpWebResponse)request.GetResponse();
byte[] data = new byte[response.ContentLength];
response.GetResponseStream().Read(data, 0, data.Length);
return new MemoryStream(data);
}
finally
{
if(response != null)
{
response.Close();
}
}
Any assistance would be greatly appreciated!