Hi,
This is my console application where i am trying to download file form the rest webservice.
But it is not downloading all content of the file my file size of 2.25GB, some time it 103 MB or 1.75GB.
This line of code throw exception
"InternalSocket = '((System.Net.ConnectStream)(stream)).InternalSocket' threw an exception of type 'System.ObjectDisposedException'".
stream.Read(buffer, 0, buffer.Length)
public void DownloadFile()
{
var product = new object();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Concat(SERVER - URL, "download/LgFiles"));
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.Headers.Add("fileid", product.fileid);
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.ServicePoint.ConnectionLimit = 1;
request.ServicePoint.Expect100Continue = false;
FileDTO file = new FileDTO();
file.fileid = product.fileid;
string path = @"C:\try\ZipDownloads\" + product.fulfilled;
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
streamWriter.Write(string.Concat("obj=", new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(file)));
try
{
var response = request.GetResponse();
long counter = 1;
long dwnlddSize = 0;
using (Stream stream = response.GetResponseStream())
{
using (MemoryStream memoryStream = new MemoryStream())
{
Byte[] buffer = new Byte[16348];
Int32 bytesRead;
Stopwatch watch = new Stopwatch();
using (FileStream fs = new FileStream(path + "\\" + product.filename, FileMode.CreateNew, FileAccess.Write))
{
watch.Start();
while (dwnlddSize < long.Parse(product.filesize))
{
bytesRead = stream.Read(buffer, 0, buffer.Length);
fs.Write(buffer, 0, bytesRead);
dwnlddSize += bytesRead;
}
Console.WriteLine("TimeTaken is " + watch.Elapsed.ToString());
}
}
}
}
catch
{
}
}