CSV File Link not Always Working Programmatically
GentleMen,
According to Upper Written Post Of brother rohitoberoi6592 I tried it progammatically
i am using c# 2005. if the dates are filled correctly First Webrequest works correctly always but when it comes to downloading csv file it sometimes succeds and sometimes it does not what might i be doing wrong and i only
want data for "EQ" series therefore i appended EQ for series.I dont have problem of ports or firewalls.i have switched off firewal to test it
private void Download_Data_button_Click(object sender , EventArgs e)
{
FromDate_prop = FromDate_prop.Trim () ;
ToDate_prop = ToDate_prop.Trim () ;
ScripCodeToGetDataFor_prop = ScripCodeToGetDataFor_prop.Trim () ;
string RequestStr_1 = string.Format (
@"http://www.nseindia.com/marketinfo/equities/scripvol/histscrip.jsp?FromDate={0}&ToDate={1}&check=new&data-type=PriceVolumeDeliverable&inputtext={2}&ser=return+document.scripform.series.options[document.scripform.series.selectedIndex].value&series=EQ"
, FromDate_prop
, ToDate_prop
, ScripCodeToGetDataFor_prop
) ;
string RequestStr_2 = string.Format (
@"http://www.nseindia.com/content/equities/scripvol/datafiles/{0}-TO-{1}{2}EQN.csv"
,FromDate_prop
,ToDate_prop
,ScripCodeToGetDataFor_prop
) ;
WebRequest Request_1 = WebRequest.Create( RequestStr_1 ) ;
Request_1.Proxy = WebRequest.DefaultWebProxy;
HttpWebResponse Response_1 = (HttpWebResponse)Request_1.GetResponse() ;
System.IO.Stream Stream_1 = Response_1.GetResponseStream() ;
System.Text.Encoding Encoding_Obj_1 = System.Text.Encoding.GetEncoding( "utf-8" ) ;
System.IO.StreamReader Reader_1 = new System.IO.StreamReader( Stream_1, Encoding_Obj_1 ) ;
string Str_1 = Reader_1.ReadToEnd();
// up to this place it is always working
#region two
WebRequest Request_2 = WebRequest.Create( RequestStr_2 ) ;
Request_2.Proxy = WebRequest.DefaultWebProxy;
// here it almost always gives error as 402 or 404 that Protocol error etc... but again sometimes it succeeds.i am confused
HttpWebResponse Response_2 = (HttpWebResponse)Request_2.GetResponse() ;
System.IO.Stream Stream_2 = Response_2.GetResponseStream() ;
System.Text.Encoding Encoding_Obj_2 = System.Text.Encoding.GetEncoding( "utf-8" ) ;
System.IO.StreamReader Reader_2 = new System.IO.StreamReader( Stream_2, Encoding_Obj_2 ) ;
string Str_2 = Reader_2.ReadToEnd();
Form fo1 = new Form () ;
fo1.Controls.Add ( new RichTextBox() ) ;
((RichTextBox )fo1.Controls[0]).Text = Str_2 ;
((RichTextBox )fo1.Controls[0]).Dock = DockStyle.Fill ;
((RichTextBox )fo1.Controls[0]).ScrollBars = RichTextBoxScrollBars.Both ;
fo1.Visible = true ;
#endregion
Response_1.Close () ;
Response_2.Close () ;
Reader_1.Dispose () ;
Reader_1.Close () ;
Reader_2.Dispose () ;
Reader_2.Close () ;
Stream_1.Close () ;
Stream_2.Close () ;
}
requesting a quick response Please
Thanking you
RIGHT_THEN