Support Forum [ All Topics | New Topic ]

Thread: Exception System.OutOfMemoryException in C# .net

Always showing Exception 'System.OutOfMemoryException' in C# .net and taking too much time for end the process.Please provide me a solution and sample code.

>> add a comment
Damin
08/11/2015 06:42


4 Replies:

what service do you use?

>> add a comment
Ephraim
8/11/2015 7:44:00 AM
string URLAuth = "https://technet.rapaport.com/HTTP/Authenticate.aspx";
WebClient webClient = new WebClient();
NameValueCollection formData = new NameValueCollection();
formData["Username"] = "my user name";
formData["Password"] = "my password";
byte[] responseBytes = webClient.UploadValues(URLAuth, "POST", formData);
string ResultAuth = Encoding.UTF8.GetString(responseBytes);
string URL = "http://technet.rapaport.com/HTTP/DLS/GetFile.aspx";
WebRequest webRequest = WebRequest.Create(URL);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
Stream reqStream = webRequest.GetRequestStream();
string postData = "ticket=" + ResultAuth;
byte[] postArray = Encoding.ASCII.GetBytes(postData);
reqStream.Write(postArray, 0, postArray.Length);
reqStream.Close();
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
Stream stream = webResponse.GetResponseStream();
StreamReader reader = new StreamReader(stream);
string content = reader.ReadToEnd();


the above code i have used.


>> add a comment
Damin
8/11/2015 7:48:00 AM
for long file you can use this :
string URLAuth = "https://technet.rapaport.com/HTTP/Authenticate.aspx";
WebClient webClient = new WebClient();
NameValueCollection formData = new NameValueCollection();
formData["Username"] = "XXX";
formData["Password"] = "YYY";
byte[] responseBytes = webClient.UploadValues(URLAuth, "POST", formData);
string ResultAuth = Encoding.UTF8.GetString(responseBytes);
//After receiving an encrypted ticket, you can use it to authenticate your session.
//Now you can choose to change the protocol to HTTP so it works faster.
//Download File
string URL = "http://technet.rapaport.com/HTTP/DLS/GetFile.aspx";
WebRequest webRequest = WebRequest.Create(URL);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
Stream reqStream = webRequest.GetRequestStream();
string postData = "ticket=" + ResultAuth;
byte[] postArray = Encoding.ASCII.GetBytes(postData);
reqStream.Write(postArray, 0, postArray.Length);
reqStream.Close();
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); ;
Stream stream = webResponse.GetResponseStream();
StreamReader reader = new StreamReader(stream);
// for long files
List<string> list = new List<string>();
string line;
while ((line = reader.ReadLine()) != null)
{
list.Add(line); // Add to list.
}
File.AppendAllLines(@"C:\\test\\MyFile.csv", list);


>> add a comment
Reuven
8/11/2015 8:07:00 AM
Thanks Reuven.
Its working fine.


>> add a comment
Damin
8/11/2015 8:40:00 AM