Questions tagged [streamreader]

StreamReader is a C# class designed for character input in a particular encoding, it can be used for reading lines of information from a standard text file. By default, a StreamReader is not thread safe.

Implements a TextReader that reads characters from a byte stream in a particular encoding.

StreamReader is designed for character input in a particular encoding, whereas the Stream class is designed for byte input and output. StreamReader can be used for reading lines of information from a standard text file.

StreamReader defaults to UTF-8 encoding unless specified otherwise, instead of defaulting to the ANSI code page for the current system. UTF-8 handles Unicode characters correctly and provides consistent results on localized versions of the operating system. If you get the current character encoding using the CurrentEncoding property, the value is not reliable until after the first Read method, since encoding auto detection is not done until the first call to a Read method.

By default, a StreamReader is not thread safe. See TextReader.Synchronized for a thread-safe wrapper.

Official Microsoft documentation

1931 questions
4
votes
2 answers

Access site directory path with streamreader in asp.net

from a class within the App_Code folder in ASP.NET, how can I access the path of the root directory of the website? I tried: StreamReader sr = new StreamReader("../Questions.aspx"); But it gave me the path in Program Files... So how can I do…
GianT971
  • 4,385
  • 7
  • 34
  • 46
4
votes
2 answers

Using xpath on a stream

is it possible to use xpath on a streamed xml file using streamreader (file obtained from the internet) ? I know the exact location of the data i need but not sure how best to get at it? Thanks
simon
  • 185
  • 3
  • 9
4
votes
3 answers

C# Roll back Streamreader 1 character

For a C# project i am using streamreader, i need to go back 1 character (basicly like undoing) and i need it to change so when you get the next character it is the same one as when you rolled back For example Hello There we do…
Steven
  • 41
  • 3
4
votes
3 answers

Cannot read txt files from C:\Testing\Docs using C#.Net

I have a C# .Net 4.0 Project which needs to read text files and parse them - very simple. The files are located in C:\Testing\Docs When I try to open a text file in the above directory I get the following error: Request for the permission of type…
DreX
  • 333
  • 1
  • 5
  • 17
4
votes
2 answers

Is there an async equivalent of StreamReader's Peek method?

I'm updating some netstandard2.0 code to not read from the HttpRequest.Body (a Stream) synchronously (this throws exceptions in netcoreapp3.0 unless you set the AllowSynchronousIO option which is obviously not a good idea). I've converted the JSON…
benmccallum
  • 1,241
  • 12
  • 27
4
votes
1 answer

Powershell - Is there a benefit to using the Peek method over Readline (while not null)?

I've been working on a PowerShell script using Streamreader (and StreamWriter) to parse a large file into smaller reports. While doing some searching around on the best way to put this thing together, I've found there are two methods largely used to…
LakeWater
  • 43
  • 3
4
votes
2 answers

HttpResponseMessage - Decompression of Gzip respone from an API Call throws the following exceptiong - The response ended prematurely

I am actually consuming a REST Service from which I receive the response compressed as Gzip so, following is my code HttpClientHandler handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip |…
4
votes
1 answer

C# stream reader ReadToEnd() missing last character

I am trying to decrypt a string in C# using AES: public static string AesDecrypt(byte[] cipherText, byte[] Key, byte[] IV) { string plaintext = null; // Create an Aes object with the specified key and IV using Aes aesAlg =…
Eutherpy
  • 4,471
  • 7
  • 40
  • 64
4
votes
4 answers

Reset StreamReader for multiple XmlReader.Read() usages

I'd like to re-use a StreamReader I've associated with an XML file for .Read()-Calls from System.Xml.XmlReader. Basically I've put together a small extension method featuring the following code: public static string GetValueByPath(this StreamReader…
Dennis Röttger
  • 1,975
  • 6
  • 32
  • 51
4
votes
1 answer

Read csv stream line by line to create an array for Excel Range

This is my first post - I will be happy to make any corrections required for any mistakes made in the post. I have been looking through the forums here for a few months and have learned a lot but I cannot seem to accomplish my goal with what I have…
Joe J
  • 41
  • 3
4
votes
2 answers

Execute Process Chain

public void ExecuteProcessChain(string[] asProcesses, string sInRedirect, string sOutRedirect) { Process p1 = new Process(); p1.StartInfo.UseShellExecute = false; p1.StartInfo.RedirectStandardOutput = true; …
Shahar Shmaram
  • 233
  • 1
  • 4
  • 10
4
votes
1 answer

C# - Parallelizing While Loop with StreamReader causing High CPU

SemaphoreSlim sm = new SemaphoreSlim(10); using (FileStream fileStream = File.OpenRead("...")) using (StreamReader streamReader = new StreamReader(fileStream, Encoding.UTF8, true, 4096)) { String line; while ((line =…
user8549339
4
votes
3 answers

How to convert Streamreader data to XmlDocument?

In C#, I am trying to get call a webservice which returns an XML file. I can make a HttpWebRequest to the webservice and store the output in a StreamReader. But how can I convert this data into an XMLDocument?
Troyes22
  • 43
  • 1
  • 1
  • 3
4
votes
2 answers

C# - Reading HTTP requests with StreamReader

I am writing a TCP Client and a Server in C# which use manually written HTTP requests to communicate with each other. The trouble I have is with reading from the Network Stream using StreamReader. So far, I have tried many methods but to no avail.…
4
votes
1 answer

Load Image from Stream/StreamReader to Image OR RawImage component

I'm using AWS Unity (v3.3.50.0): S3 SDK (AWSSDK.S3.3.3.5.4.unitypackage) downloaded from https://aws.amazon.com/mobile/sdk/. My Unity version is 5.5.1. I want to download an image placed on S3 bucket, bucket is configured and can be downloaded. And…
eagle
  • 567
  • 1
  • 6
  • 24