473,503 Members | 11,281 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.GetBytes(postData);

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

Stream readStream = httpWebRequest.GetRequestStream();

// Send the data.
readStream.Write(data, 0, data.Length);
readStream.Close();

HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
//Stream stream = httpWebResponse.GetResponseStream();
StreamReader stream = new StreamReader(httpWebRequest.GetResponse().GetRespo nseStream());

Console.WriteLine("Content Length: " + httpWebResponse.ContentLength.ToString());
Console.WriteLine("Content Encoding: " + httpWebResponse.ContentEncoding.ToString());
Console.WriteLine("Content Type: " + httpWebResponse.ContentType.ToString());
Console.WriteLine("Character Set: " + httpWebResponse.CharacterSet.ToString());
Console.WriteLine("Headers: " + httpWebResponse.Headers.ToString());
Console.WriteLine("Last Modified: " + httpWebResponse.LastModified.ToString());
Console.WriteLine("ResponseUri: " + httpWebResponse.ResponseUri.ToString());
Console.WriteLine("Server: " + httpWebResponse.Server.ToString());
Console.WriteLine("Status Code: " + httpWebResponse.StatusCode.ToString());
Console.WriteLine("Status Description: " + httpWebResponse.StatusDescription.ToString());

FileStream writeStream = new FileStream(destination, FileMode.OpenOrCreate, FileAccess.Write);

// 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.Write(buffer, 0, count);
//Console.WriteLine(outputData);
count = stream.Read(readBuff, 0, 256);
}

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

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

<Id>6JcNjOEwpk6Lkqy1V9JPkQ==</Id>
Nov 19 '05 #1
1 1480
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.Write(buffer, 0, count);
//Console.WriteLine(outputData);
count = stream.Read(readBuff, 0, 256);
}


Notice that you're doing writeStream.Write(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
10659
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...
4
2275
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...
2
2464
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() { ...
3
1876
by: Luqman | last post by:
How can I retrieve text from html file and write to textbox. Best Regards, Luqman
1
3296
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...
4
8351
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...
1
2383
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...
1
2567
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...
6
2204
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...
1
4199
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
7294
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
7361
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...
0
7470
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...
0
5602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
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...
0
4693
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3183
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...
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
403
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...

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.