Question Downloading a CSV file

glucobear

New member
Joined
Oct 20, 2011
Messages
3
Programming Experience
1-3
Hi. I have been trying to figure out how to do this for the past two days.. :( Please help.

I want to download a file from a financial site. When I paste the URL in a browser, the file is downloaded. However, when I use webClient.DownloadFile or even HTTPPosts...it returns an html page not the csv file. Please lead me to the right direction. Thank you very much.
 
Presumably the URL is for a page that tells the browser to download the file. No browser means no download. Perhaps you could provide us with the URL so we don't have to guess.
 
The site is on this line of code.

Dim wr As HttpWebRequest = DirectCast(WebRequest.Create("http://www.barchart.com/historicaldata.php?file=dstk&date=102011"), HttpWebRequest)

I supplied the necessary credentials (as the site needs me to login).

On the download page, I only need to click on a link to download the CSV. Pasting the above-mentioned URL works fine as well.
But when I do it through an app, it returns HTML. I'm stumped. :(
 
Before I proceed, may I say thank you for replying to my questions. Really appreciate it.

Here's what I get -

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="x-ua-compatible" content="IE=8" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta http-equiv="refresh" content="600">
<meta name="description" content="My Barchart Login: Access your free Stocks and Commodities Portfolios, Screeners, Historical Data, Chart Builder, Advanced Technicals and more" />
<meta name="keywords" content="barchart, barcharts, login, futures, stocks, forex, etfs, mutual funds, register, free account, free membership, free registration, My Barchart, portfolios, screeners, historical data, technical analysis, charts, quotes" />
<meta name="robots" content="all,follow" />
<meta name="rating" content="Safe for Kids" />
<link rel="meta" href="/shared/rdf/labels.rdf" type="application/rdf+xml" title="ICRA labels" />
<meta http-equiv="pics-Label" content='(pics-1.1 "http://www.icra.org/pics/vocabularyv03/" l gen true for "http://www.barchart.com" r (n 0 s 0 v 0 l 0 oa 0 ob 0 oc 0 od 0 oe 0 of 0 og 0 oh 0 c 0) gen true for "http://www.www.barchart.com" r (n 0 s 0 v 0 l 0 oa 0 ob 0 oc 0 od 0 oe 0 of 0 og 0 oh 0 c 0))' />
<title> My Barchart - Registration | My Barchart Login</title>
<link rel="stylesheet" href="/shared/css/style.css" type="text/css" />
<link rel="stylesheet" href="/shared/css/autocomplete.css" type="text/css" />
<link rel="stylesheet" href="/shared/css/print.css" type="text/css" media="print" />
<!--[if IE 6]>
<link rel="stylesheet" href="/shared/css/ie6style.css" type="text/css" />
<link rel="stylesheet" href="/shared/css/ie6menus.css" type="text/css" />
<link rel="stylesheet" href="/shared/css/ie6text.css" type="text/css" />
<![endif]-->


<!--[if lte IE 7]>
<link rel="stylesheet" href="/shared/css/ie7style.css" type="text/css" />
<![endif]-->


<link rel="stylesheet" href="/shared/js/protomultiselect/test.css" type="text/css" />

<script type="text/javascript" src="/shared/js/thirdpartyfunctions.js"></script>
<!-- <script type="text/javascript" src="/shared/js/ajaxSuggestions.js"></script> -->


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.3/scriptaculous.js"></script>

<script type="text/javascript" src="/shared/js/com.barchart.js"></script>


<script type="text/javascript">

var Barchart = {
Content : [],
Highlights : new com.barchart.QuoteHighlights(),
InitObjects : [],
Page : {},




Init : function() {
Barchart.Data.DataMaster = new com.barchart.DataMaster();


for (var k in Barchart.Content) {
var c = Barchart.Content[k];
if (c.Init)
c.Init();
}


for (var i = 0; i < Barchart.InitObjects.length; i++) {
Barchart.InitObjects.Init();
}




if (Barchart.Page.Init)
Barchart.Page.Init();


Barchart.Data.DataMaster.start();
Barchart.Stubs.DisplayAds();


},


Site : {},


User : {
username : null,
Views : {
}
}
};


Barchart.Data = {
DataMaster : null
};


Barchart.Stubs = {
Symbol : 'null',


ReturnSearchLocation: function(symbol) {
var type = 'stocks';
if (symbol.substr(0,1) == '^')
type = 'forex';
else if (symbol.length == 5 && symbol.substr(-1) == 'X')
type = 'funds';
else if (symbol.match(/^[a-zA-Z].*[0-9]$/))
type = 'futures';


var locate = document.URL.replace(/(\n|\r)+$/, ''); //clear begin/end whitespace


if (locate.match(/.php/gi) && !locate.match(/lookup|historical|allrates|sectors\/finder/gi)) {
var urlPart = locate.split('?');
if (urlPart[1] != null){
var queryAttrValPair = urlPart[1].split('&');
var symVal = queryAttrValPair[0].split('=');
if (symVal[0] == 'sym'){
symVal[1] = symbol;
var assembledUrl = urlPart[0] + '?' + symVal[0] + '=' + symVal[1];
for (i=0; i < queryAttrValPair.length; i++)
if (i)
assembledUrl += '&' + queryAttrValPair;
document.location.href = assembledUrl;
}
else
document.location.href = '/quotes/' + type + '/' + symbol;
}
else
document.location.href = '/quotes/' + type + '/' + symbol;
}
else {
if (locate.match(/\/opinions/gi))
document.location.href = '/opinions/' + type + '/' + symbol;
else if (locate.match(/\/snapopinion/gi))
document.location.href = '/snapopinion/' + type + '/' + symbol;
else if (locate.match(/\/performance/gi))
document.location.href = '/performance/' + type + '/' + symbol;
else if (locate.match(/\/technicals/gi))
document.location.href = '/technicals/' + type + '/' + symbol;
else if (locate.match(/\/detailedquote/gi))
document.location.href = '/detailedquote/' + type + '/' + symbol;
 
That looks like a login page. I would suggest that you are not providing credentials correctly. I don't do that sort of thing much myself so I'm no expert but maybe you need to login first to generate a session cookie and then use that when downloading.
 
Back
Top