473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to download http file.

Hello,

I am trying to download the file (automatically using my program) and fileName has built in date in the file name. when ever I schedule the exe file, it does not run; does anybody have any clue why it does not run?

public static void Main(string[] args)
{
DateTime dt = DateTime.Now;
string date = dt.ToString("yyyymmdd");

string fileName = "" + date + "isolf.csv";
//Console.WriteLine(fileName);
//Console.ReadLine();
string location = "http://mis.nyiso.com/public/csv/isolf/";
//string fileName2 = args[1] + "isolf.csv";
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(location+fileNam e);
HttpWebResponse ws = (HttpWebResponse)wr.GetResponse();
Stream str = ws.GetResponseStream();
byte[] inBuf = new byte[100000];
int bytesToRead = (int)inBuf.Length;
int bytesRead = 0;
while (bytesToRead 0)
{
int n = str.Read(inBuf, bytesRead, bytesToRead);
if (n == 0)
break;
bytesRead += n;
bytesToRead -= n;
}
FileStream fstr = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
fstr.Write(inBuf, 0, bytesRead);
str.Close();
fstr.Close();
}
Oct 7 '08 #1
2 1253
Note that "mm" isn't months - you want "MM".

Call me lazy, but I'd just use WebClient - something like:

string file = DateTime.Today.ToString("yyyyMMdd") +
"isolf.csv";
using (WebClient client = new WebClient())
{
client.BaseAddress = "http://mis.nyiso.com/public/csv/
isolf/";
client.DownloadFile(file, file);
}

(possibly deleting the file first if it already exists)

Marc Gravell
[C# MVP]
Oct 7 '08 #2
Does the program not even start or it fails?
How are you scheduling it?
How are you determining it doesnt run?
Why not put some logging in it and check it the log file contains anything,
potentially log all exceptions that occur in Main by wrapping the contents in
a try catch and logging it.
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Anil S" wrote:
Hello,

I am trying to download the file (automatically using my program) and fileName has built in date in the file name. when ever I schedule the exe file, it does not run; does anybody have any clue why it does not run?

public static void Main(string[] args)
{
DateTime dt = DateTime.Now;
string date = dt.ToString("yyyymmdd");

string fileName = "" + date + "isolf.csv";
//Console.WriteLine(fileName);
//Console.ReadLine();
string location = "http://mis.nyiso.com/public/csv/isolf/";
//string fileName2 = args[1] + "isolf.csv";
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(location+fileNam e);
HttpWebResponse ws = (HttpWebResponse)wr.GetResponse();
Stream str = ws.GetResponseStream();
byte[] inBuf = new byte[100000];
int bytesToRead = (int)inBuf.Length;
int bytesRead = 0;
while (bytesToRead 0)
{
int n = str.Read(inBuf, bytesRead, bytesToRead);
if (n == 0)
break;
bytesRead += n;
bytesToRead -= n;
}
FileStream fstr = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
fstr.Write(inBuf, 0, bytesRead);
str.Close();
fstr.Close();
}
Oct 7 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Aaron | last post by:
On my website I have a dynamic link(aspx) to this file 0AX120S.jpg(privacy protection). When a visitor clicks on the link I want them to see my_vacation_pic.jpg (fetch realname from database) is...
5
by: Simon Wigzell | last post by:
Allowing download of file types that will display in a browser is no problem, but how about files types that don't display? I would like my clients to be able to click on a link that will start a...
4
by: Kevin Muenzler, WB5RUE | last post by:
How do I force a browser to download a file instead of displaying it? In other words I have a page with MP3 and WMA files on it and I would like for the visitor to download the file instead of...
0
by: jmd | last post by:
Hello. I want to write a C# program that does completely automatically what, until now, I do manually, witch is describe below : 1. I launch IE (6) 2. I browse to my desired download page, say...
1
by: Tom | last post by:
Hi, I have a website providing pdf file downloading for registered member. Member needs to login and be able to download pdf file. I save pdf file in a directory. e.g....
1
by: a.r.austin | last post by:
Hello, I am trying to download a few files one after another from a remote server. Problem is that I don't know how to, or if I am able at all, set a time out for download. I don't want to time...
16
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will...
0
by: kain razial | last post by:
ANYOTHER NEEDS ALSO CONTACT ME.I WILL HELP YOU TO GET THAT TEKLA XSTEEL V 12 DOWNLOAD LINK. http://www.sendspace.com/file/zem32r
0
by: kain razial | last post by:
ANYOTHER NEEDS ALSO CONTACT ME.I WILL HELP YOU TO GET THAT TEKLA XSTEEL V 12 DOWNLOAD LINK. http://www.sendspace.com/file/zem32r
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.