473,657 Members | 2,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading text file from server

I ma having an issue saving a text file that is located on a remove server (Chase Bank) to one of my servers. I know that I have the file in the Srtream object but I just can't seem to get it to save to my server. Here is my code:
ASCIIEncoding encoding = new ASCIIEncoding() ;
byte[] data = encoding.GetByt es(postData);

// Prepare web request...
HttpWebRequest httpWebRequest = (HttpWebRequest )WebRequest.Cre ate(chaseUrl);
httpWebRequest. Method = "POST";
httpWebRequest. ContentType = "applicatio n/x-www-form-urlencoded";
httpWebRequest. ContentLength = data.Length;
httpWebRequest. Timeout = 60000;

Stream readStream = httpWebRequest. GetRequestStrea m();

// Send the data.
readStream.Writ e(data, 0, data.Length);
readStream.Clos e();

HttpWebResponse httpWebResponse = (HttpWebRespons e)httpWebReques t.GetResponse() ;
//Stream stream = httpWebResponse .GetResponseStr eam();
StreamReader stream = new StreamReader(ht tpWebRequest.Ge tResponse().Get ResponseStream( ));

Console.WriteLi ne("Content Length: " + httpWebResponse .ContentLength. ToString());
Console.WriteLi ne("Content Encoding: " + httpWebResponse .ContentEncodin g.ToString());
Console.WriteLi ne("Content Type: " + httpWebResponse .ContentType.To String());
Console.WriteLi ne("Character Set: " + httpWebResponse .CharacterSet.T oString());
Console.WriteLi ne("Headers: " + httpWebResponse .Headers.ToStri ng());
Console.WriteLi ne("Last Modified: " + httpWebResponse .LastModified.T oString());
Console.WriteLi ne("ResponseUri : " + httpWebResponse .ResponseUri.To String());
Console.WriteLi ne("Server: " + httpWebResponse .Server.ToStrin g());
Console.WriteLi ne("Status Code: " + httpWebResponse .StatusCode.ToS tring());
Console.WriteLi ne("Status Description: " + httpWebResponse .StatusDescript ion.ToString()) ;

FileStream writeStream = new FileStream(dest ination, FileMode.OpenOr Create, FileAccess.Writ e);

// Used with the StreamReader Object
Char[] readBuff = new Char[256];
byte [] buffer = new byte[256];
int count = stream.Read( readBuff, 0, 256 );

while (count > 0)
{
String outputData = new String(readBuff , 0, count);
writeStream.Wri te(buffer, 0, count);
//Console.WriteLi ne(outputData);
count = stream.Read(rea dBuff, 0, 256);
}

--------------------------------
From: Joe Ehrenfeld

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>6JcNjOEwpk6 Lkqy1V9JPkQ==</Id>
Nov 19 '05 #1
1 1488
Hello Joe Ehrenfeld via .NET 247,
// Used with the StreamReader Object
Char[] readBuff = new Char[256];
byte [] buffer = new byte[256];
int count = stream.Read( readBuff, 0, 256 );
while (count > 0)
{
String outputData = new String(readBuff , 0, count);
writeStream.Wri te(buffer, 0, count);
//Console.WriteLi ne(outputData);
count = stream.Read(rea dBuff, 0, 256);
}


Notice that you're doing writeStream.Wri te(buffer, 0, count);

also notice that you never assign buffer outside of the initial value.

--
Matt Berther
http://www.mattberther.com
Nov 19 '05 #2

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

Similar topics

2
10679
by: Roland Hall | last post by:
I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already found one bug, although stated the bug was only in ODBC, which I'm not using. It appears to be in the OLEDB driver also. My connection was: conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & ";" & "Extended Properties='Text;HDR=NO;FMT=Delimited'"
4
2293
by: JoelWhitehouse | last post by:
Hi! I want to write a script that will read a .php file on a remote server and print to the current page a portion of the text contained in the remote file. I am just wondering what the best method is for reading from a file in this case - the file is only a few bytes long. I've seen a tutorial or two that only tangentially addresses my problem, and even then each one has varied greatly as to which object they utilize. Any ideas to...
2
2477
by: Sabin Finateanu | last post by:
Hi I'm having problem reading a file from my program and I think it's from a procedure I'm using but I don't see where I'm going wrong. Here is the code: public bool AllowUsage() { OperatingSystem os = Environment.OSVersion; AppDomain ad = Thread.GetDomain();
3
1880
by: Luqman | last post by:
How can I retrieve text from html file and write to textbox. Best Regards, Luqman
1
3315
by: Trevor | last post by:
I posted this message last week but seem to be missing a few days posts. We currently run our web site in php and are now converting it to asp.net to match the rest of our business that is .net based. I have tried using the following code layout to open the file I require but get an illigal character exception when I try and open the file. Dim sFileName As String =...
4
8363
by: Jason Kumpf | last post by:
OK I've been staring at this code all day and still with everything I have tried I cannot figure out two problems I am having. Once is why the space limit for the directory I create in the code fails. Second, why the data reader is reading every other record. Here is all of the source code for my little application followed by the contents of the log file that it dumps out:...
1
2399
by: svijay | last post by:
hi I have got a strange problem. May I know any solution for this. Here is the detailed description about the problem We have got a mainframe system and also production and development server.
1
2580
by: j7.henry | last post by:
I am trying to pull specific data that is in a comma delimited file into a web page. So if my comma delimited file looks like: Name,Address,Zip Fred,123 Elm,66666 Mike,23 Jump,11111 I would like to be able to read this data and put each row into a variable? so I could display the values in a web page where I want.
6
2210
by: Jason | last post by:
I would like to build a windows app or service that would read a .txt file and than put the contents of that file in an email and send off the email. WOuld that be very difficult?...how could this be done?
1
4209
AnuSumesh
by: AnuSumesh | last post by:
Hi, I want to read the text property of XML file. My xml file is as follows: <?xml version="1.0"?> <Domain_Credentials> <User> anu </User>
0
8394
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8825
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6164
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4152
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.