473,387 Members | 1,512 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.

reading a file from a url to array

58
Hey All,
I have been trying to research how to get a file (basically a csv file) from a url to an array and my search has come up with some examples, but not quite what I am looking for. Would appreciated any direction and or other examples of folks that have done this before.
Basically we have a cloud computer set up (Hadoop) and the output of some of our processes is what I am trying to get to..
the file is something like
http://ourserver...com:port#/filetos...es/actual_file

so if you put that in a browser, a 'save file dialog comes up' so i know the link if valid.
In .net was looking into using SYSTEM.NET and a simple downloadfile sub
Expand|Select|Wrap|Line Numbers
  1. Public Sub DownLoadFile(ByVal address As String, _
  2.                             ByVal fileName As String)
  3.  
  4.  
  5. End Sub
but that just downloads it to a local file... which is what I want to do, but first have to to load each row into an array and manipulate the data just a bit....
also read this bit of code somewhere but it has to do with images and again it only downloads doesn't really interact with the stream

Expand|Select|Wrap|Line Numbers
  1.         Dim wr As HttpWebRequest = CType(WebRequest.Create(sfile), HttpWebRequest)
  2.         Dim ws As HttpWebResponse = CType(wr.GetResponse(), HttpWebResponse)
  3.         Dim str As Stream = ws.GetResponseStream()
  4.         Dim inbuf(1000000) As Byte
  5.         Dim bytesToRead As Integer = CInt(inbuf.Length)
  6.         Dim bytesRead As Integer = 0
  7.         While bytesToRead > 0
  8.             Dim n As Integer = str.Read(inbuf, bytesRead, bytesToRead)
  9.             If n = 0 Then
  10.                 Exit While
  11.             End If
  12.             bytesRead += n
  13.             bytesToRead -= n
  14.         End While
would definitely love some help!!!
Thanks ahead of time,
Eric
Jun 28 '10 #1
1 1178
erbrose
58
alright after a bit more web searches.. found it, so thought I would share if other folks ever need to do this.
Expand|Select|Wrap|Line Numbers
  1. Imports System
  2. Imports System.IO
  3. Imports System.Net
  4.  
  5. Dim uriWebSite As New Uri("http://ourserver...com:port#/filetos...es/actual_file")
  6.         Dim WReq As WebRequest = System.Net.WebRequest.Create(uriWebSite)
  7.         Dim wResp As WebResponse = WReq.GetResponse()
  8.         Dim sr = New StreamReader(wResp.GetResponseStream())
  9.         Dim sw = New StreamWriter("d:/temp/test.csv")
  10.  
  11.         Dim line As String = ""
  12.  
  13.         While Not sr.EndOfStream()
  14.  
  15.             line = sr.ReadLine()
  16.             line = do some process
  17.             sw.Write(line)
  18.             sw.WriteLine()'not sure why but tried adding just a new line character to the the line and it didn't work, so just added writeline and it works fine
  19.  
  20.         End While
  21.  
  22.         sr.Close()
  23.         sw.Close()
  24.  
Jun 28 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: deko | last post by:
Do I need to use flock() when reading a file into an array? It's possible that the file in question could be open at the time the file('filename') request is made. I realize flock() is required...
6
by: Dave Reid | last post by:
Hi everyone... I'm pretty much a newbie C++ user, and I've run into a problem. I'm trying to read in a large text file, and then do manipulations on it. I can read it into a large 2-dimensional...
12
by: Eigenvector | last post by:
I've been dinking around with this code for a while now and I can't seem to figure out where the problem lies. The original problem was that I for some reason or another couldn't allocate few...
11
by: Matt DeFoor | last post by:
I have some log files that I'm working with that look like this: 1000000000 3456 1234 1000000001 3456 1235 1000020002 3456 1223 1000203044 3456 986 etc. I'm trying to read the file...
2
by: novacreatura | last post by:
Hi, I have a project that's supposed to create a program for a "Dating Service". The first part of the program is to read a textfile of profiles which include names, age, etc...into a string...
15
by: Shuch | last post by:
Hi all, i m trying to read from a file and then copy it into an array...my code is as follow..it runs fine but i cant understand y it doesnt show me any output?? here is my code... using...
1
by: sreedivya | last post by:
hi all how to declare and reading an array values in sql server thanks in advance
3
by: miss time | last post by:
Hi all, my java friends ^-^ I have next week quiz in reading file text ,and understand the topic very well. can any one give some question related to this topic .this help me more to...
3
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I'm trying to write an array of structures named myStructArray to a binary file and later on read it back. Although I could complete the entire project in C in about 2 minutes, I...
1
Coldfire
by: Coldfire | last post by:
Hi, The strange problem i am having is, the input element of type='file' not reading file names after 20 file elements. It simple returns null on reading the 'name' of file. The code is...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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.