Hi Saumya,
Please refer the below code.
Code
protected void btngetdata_Click(object sender, EventArgs e)
{
DateTime start = DateTime.ParseExact(DateTime.Now.ToShortDateString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
DateTime end = DateTime.ParseExact(DateTime.Now.ToShortDateString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
string url = string.Empty;
for (DateTime counter = start; counter <= end; counter = counter.AddDays(1))
{
url = string.Format("https://mars.ccavenue.com/servlet/ccav.MerchantReconReport?User_Id=M_npa20362_20362&Date=" + counter);
}
using (var client = new WebClient())
using (var file = File.Create(@"F:\Users\dharmendra\Desktop\data.csv"))
{
var bytes = client.DownloadData(url);
file.Write(bytes, 0, bytes.Length);
}
}
Or
protected void btngetdata_Click(object sender, EventArgs e)
{
DateTime start = DateTime.ParseExact(DateTime.Now.ToShortDateString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
DateTime end = DateTime.ParseExact(DateTime.Now.ToShortDateString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
string url = string.Empty;
for (DateTime counter = start; counter <= end; counter = counter.AddDays(1))
{
url = string.Format("https://mars.ccavenue.com/servlet/ccav.MerchantReconReport?User_Id=M_npa20362_20362&Date=" + counter);
}
using (var client = new WebClient())
{
try
{
client.DownloadFile(url, @"F:\Users\dharmendra\Desktop\data.csv");
}
catch (Exception ex)
{
while (ex != null)
{
Console.WriteLine(ex.Message);
ex = ex.InnerException;
}
}
}
}
Please refer the below links for web api.
http://www.codeproject.com/Articles/588909/ASP-NET-WEB-API-Basics-MVC
http://www.codeproject.com/Articles/769671/Web-API-without-MVC
http://www.codeproject.com/Articles/720356/ASP-NET-Web-API