I would like to download file located for example at: http://stooq.pl/db/d/?d=20120216&t=dh
Like we can seize this is not a direct link/path to file but - as i suppose - file is generated when we click on this link (in web browser "save dialog" has been showen).
In general I'm trying to download files from the table available at the link below:
I assume all your files are locatedi ndatabase, then you can have a generic handler to get the file content from database and set its response type and send the response to client, it will give you a save dialog on client browser...
1. I have a file located on http://stooq.pl/db/d/?d=20120216&t=5
The stooq.pl is not my website - it's external website which share stock exchange quotation files.
2. I would like to download this file into my asp.net application (load this file onto my private server, where my asp.net has been published). Secondly, read this file (it is txt file) and load data into my aspx page.
Point 2 is quite easy, but I have a problem with 1 - with download (or upload - depends on side).
It's strange, because when you try to download mentioned file (or another one, for example: http://stooq.pl/db/d/?d=20120224&t=5)
by Internet Explorer browser - the empty file (0kb size) will be downloaded, but using another web bowser e.g. Google Chrome the file size is correct - about 3MB.
I'm confused, because during writing this post I have tried once again to downloading file (by browser) and even when I'm using IE and try to download the oldest file:
i-spy
Member
37 Points
20 Posts
Download file (indirect file)
Feb 16, 2012 07:52 PM|LINK
Hi
I have a problem with download a file from url.
I would like to download file located for example at: http://stooq.pl/db/d/?d=20120216&t=dh
Like we can seize this is not a direct link/path to file but - as i suppose - file is generated when we click on this link (in web browser "save dialog" has been showen).
In general I'm trying to download files from the table available at the link below:
http://stooq.pl/db/
(any from the table).
To download file with known direct link, like : "www.somethink.com/file1.jpg" I use following code:
public static void File(string uri, string savePath) { WebClient webClient = new WebClient(); webClient.DownloadFile(new Uri(uri), savePath); }And it's work fine. But when I try to use WebClient to download file located at the 'indirect' link it is not work.
If you have any idea how to resolve my problem, please let me know.
Regards,
i-spy
Prashant Kum...
Star
12528 Points
2024 Posts
Re: Download file (indirect file)
Feb 18, 2012 06:52 AM|LINK
Have a look at this
http://stackoverflow.com/questions/690587/using-webclient-in-c-sharp-is-there-a-way-to-get-the-url-of-a-site-after-being-r
ramiramilu
All-Star
97849 Points
14494 Posts
Re: Download file (indirect file)
Feb 18, 2012 07:04 AM|LINK
If I understood you correctly., then you want to download file from database...in that case please refer following code -
http://www.intstrings.com/ramivemula/asp-net/retrieve-files-from-a-table-in-database-using-generic-handler/
I assume all your files are locatedi ndatabase, then you can have a generic handler to get the file content from database and set its response type and send the response to client, it will give you a save dialog on client browser...
Thanks,
JumpStart
i-spy
Member
37 Points
20 Posts
Re: Download file (indirect file)
Feb 18, 2012 09:17 AM|LINK
Thank you for yours answers.
The main idea which I would like to perform is:
1. I have a file located on http://stooq.pl/db/d/?d=20120216&t=5
The stooq.pl is not my website - it's external website which share stock exchange quotation files.
2. I would like to download this file into my asp.net application (load this file onto my private server, where my asp.net has been published). Secondly, read this file (it is txt file) and load data into my aspx page.
Point 2 is quite easy, but I have a problem with 1 - with download (or upload - depends on side).
I have tried solution suggested by Prashant Kumar (at http://stackoverflow.com/questions/690587/using-webclient-in-c-sharp-is-there-a-way-to-get-the-url-of-a-site-after-being-r).
At the beginning of the code is:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://stooq.pl/db/d/?d=20120216&t=5"); req.Method = "GET"; req.AllowAutoRedirect = true; WebResponse response = req.GetResponse(); response.GetResponseStream(); Stream responseStream = response.GetResponseStream();BUT responseStream is empty - no stream.
To explain as easy as possible what exactly I need, I woud like to download, please look at the screenshot below:
this .prn file I would like to download/upload into my application.
Thanks
i-spy
Dino He - MS...
Star
8068 Points
1023 Posts
Microsoft
Re: Download file (indirect file)
Feb 21, 2012 09:00 AM|LINK
Hi
I write the demo for you.
I can get the file to D:\ called xxx.prn
Hope it helpful.
protected void Page_Load(object sender, EventArgs e) { try { WebRequest request = WebRequest.Create("http://stooq.pl/db/d/?d=20120216&t=5"); WebResponse response = request.GetResponse(); Stream reader = response.GetResponseStream(); FileStream writer = new FileStream("D:\\xxx.prn", FileMode.OpenOrCreate, FileAccess.Write); byte[] buff = new byte[512]; int c = 0; while ((c = reader.Read(buff, 0, buff.Length)) > 0) { writer.Write(buff, 0, c); } writer.Close(); writer.Dispose(); reader.Close(); reader.Dispose(); response.Close(); Response.Write("yes"); } catch (Exception ex) { Response.Write("No"); } }If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
i-spy
Member
37 Points
20 Posts
Re: Download file (indirect file)
Feb 21, 2012 04:15 PM|LINK
Thank you very much for the code above. I have tried it but unfortunately It doesn't work for me - stream is still empty. File
"D:\\xxx.prn" has been created but size of file is equal zero. Loop 'while'
while ((c = reader.Read(buff, 0, buff.Length)) > 0) { writer.Write(buff, 0, c); }hasn't saved any data.
I have tried add:
WebRequest request = WebRequest.Create("http://stooq.pl/db/d/?d=20120216&t=5"); request.Method = WebRequestMethods.Http.Get; request.Headers.Add("Accept-Language", "en-US");and also:
HttpWebRequest request = WebRequest.Create("http://stooq.pl/db/d/?d=20120216&t=5") as HttpWebRequest;; request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.6)And It still doesn't work. Do you have any ideas??
Thanks,
i-spy
s
Dino He - MS...
Star
8068 Points
1023 Posts
Microsoft
Re: Download file (indirect file)
Feb 24, 2012 07:38 AM|LINK
Hi
I think this is because the file in http://stooq.pl/db/d/?d=20120216&t=5 is a empty file.
I download it by browser, and check the file size, 0KB.
I think that the really problem...
Hope it helpful.
Thanks
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
AneevJohn
Member
140 Points
52 Posts
Re: Download file (indirect file)
Feb 24, 2012 08:27 AM|LINK
Hi,
Simply Response.REdirect("http://stooq.pl/db/d/?d=20120216&t=dh");
will work.
Aneev John
i-spy
Member
37 Points
20 Posts
Re: Download file (indirect file)
Feb 24, 2012 03:46 PM|LINK
Hi
It's strange, because when you try to download mentioned file (or another one, for example: http://stooq.pl/db/d/?d=20120224&t=5)
by Internet Explorer browser - the empty file (0kb size) will be downloaded, but using another web bowser e.g. Google Chrome the file size is correct - about 3MB.
I'm confused, because during writing this post I have tried once again to downloading file (by browser) and even when I'm using IE and try to download the oldest file:
http://stooq.pl/db/d/?d=20120216&t=5
it's download correctly.
Unfortunately downloading file by C# code sill doesn't work.
Thanks,
i-spy
Dino He - MS...
Star
8068 Points
1023 Posts
Microsoft
Re: Download file (indirect file)
Feb 27, 2012 10:00 AM|LINK
Hi
Which version you use?
I use or my browser:
Opera firefox chrome IE 8 IE 9
still 0 kb...
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework