I'm new to C# form, recently trying to write a program which can download files from my friend's online hard drive.
But my program can only download file size lower than 1mb correctly, beyond that can only download 15bytes.
I did some research that seems to be maxRecievedMessageSize
problem, i tried to check my app.config
, and this is what i got
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
And this is my code for download
MyHttpResponse httpDownload(String url)
{
string strHtml = string.Empty;
MyHttpResponse myResponse = new MyHttpResponse();
WebRequest myWebRequest = WebRequest.Create(url);
myWebRequest.Timeout = 10000;
HttpWebRequest myHttpWebRequest = (HttpWebRequest)myWebRequest;
myHttpWebRequest.Timeout = 10000;
myHttpWebRequest.Method = "GET";
myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Windows NT 5.2; Windows NT 6.0; Windows NT 6.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; MS-RTC LM 8; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 4.0C; .NET CLR 4.0E)";
myHttpWebRequest.CookieContainer = this.cookieContainer;
WebResponse myWebResponse = myHttpWebRequest.GetResponse();
Stream myStream = myWebResponse.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myStream, Encoding.Default);
int index1 = url.LastIndexOf('/');
int index2 = url.LastIndexOf('?');
String FileName = url.Substring(index1 + 1, index2 - index1 - 1);
WebClient myWebClient = new WebClient();
//myWebClient.DownloadDataCompleted += new AsyncCompletedEventHandler(DownloadProgressCallback);
//trying to have this function but not sure how to code it right...
string filepath = textBox3.Text;
myWebClient.DownloadFileAsync(new Uri(url), filepath + "/" + FileName);
}
someone said DownloadFileAsync
can "absolutely successfully download a file so the issue is my code or my setup"
Is there anything else i can provide to give more informations?
I've saw c# - maxReceivedMessageSize and maxBufferSize in app.config, but don't really understand what it's saying.
By the way, not sure if it's about WCF though.