streamreader

StreamWriter/StreamReader File In Use By Another Process

时光总嘲笑我的痴心妄想 提交于 2019-12-13 13:21:50
问题 I have a StreamWriter object to write to a log file, it is initialised as follows: StreamWriter streamWriter = File.AppendText(GetLogFilePath()); streamWriter.AutoFlush = true; Later in my code, I need to close the log file, and then read in part of the logged out contents. I have the following code: streamWriter.Close(); streamWriter = null; StreamReader logFileStream = File.OpenText(GetLogFilePath()); This is throwing an exception: The process cannot access the file because it is being used

StreamReader complains that file does not exist, but it does

瘦欲@ 提交于 2019-12-13 11:33:31
问题 I have an application that is localized for use across Europe. I have a menu option that loads a file from disk. This operation works fine on my dev machine but does not work on the virtual machine I use to test other operating systems _ e.g French, Spanish etc. A FileNotFoundException is generated when the StreamReader tries to open the file. It says "'Could not find the file C:\Program Files\MyCompany\MyTool\bin\Files\debug.txt'" Thing is, the file does exist, at the correct location and

Streamreader doesn't read data in text file C#

狂风中的少年 提交于 2019-12-13 10:33:56
问题 I have two classes "allmethods.cs" and "caller.cs" I have two methods in the "allmethods.cs" class which are "WritingMethod" and "ReadingMethod" The program should write and read from a text file. It writes smoothly when I call the "WritingMethod" but When I call the "ReadingMethod" it shows null as if there is no data in the text file. I can't identify the problem in my code, I'd be glad if anyone help me identify the problem. Here is my code: public class allmethods { private static string

Get index of next same character [duplicate]

给你一囗甜甜゛ 提交于 2019-12-13 08:38:47
问题 This question already has answers here : Get the index of the nth occurrence of a string? (9 answers) Closed 5 years ago . I have a file like this: "Something, something, something, something, something" And I want to get the index of third "," with: StreamReader sr=new StreamReader("File.txt"); string s=sr.Readline(); string c=s.Substring(0, s.IndexOf(','))); 回答1: Sorry for previous answer, I created a function for you, try this, You need to pass your string, character to find and occurance

streamread can't read any data from NetworkStream in c# ,

柔情痞子 提交于 2019-12-13 08:29:00
问题 I have a sensor that has an ip and port 192.168.2.44:3000. I used the herculas to connect to the device ,as you can see in the picture : enter image description here I need to implement this software in c# ,so i write this code : private static void Main(string[] args) { try { byte[] buffer = new byte[2048]; // read in chunks of 2KB int bytesRead; var listener = new TcpListener(IPAddress.Any, 3000); listener.Start(); NetworkStream network_stream; StreamReader read_stream; StreamWriter write

StreamReader Server.MapPath - Physical path given, virtual path expected

怎甘沉沦 提交于 2019-12-13 05:15:06
问题 Im trying to get my .Net website to read the first line in a text file that shows a status of the computer it is located on. I get the good old "Server.MapPath - Physical path given, virtual path expected" if I remove the Server.MapPath, it fixes it the problem on the server, but then errors on the clients computer because it seems to be trying to access the file on the clients PC. Here is snippet: StreamReader StreamReader3 = new StreamReader(Server.MapPath(@"C:\\status\\status.txt"));

Streamreader with custom LineBreak - Performance optimisation

馋奶兔 提交于 2019-12-13 04:36:41
问题 Edit: See my Solution below... I had the following Problem to solve: We receive Files (mostly adress-Information) from different sources, these can be in Windows Standard with CR/LF ('\r''\n') as Line Break or UNIX with LF ('\n'). When reading text in using the StreamReader.ReadLine() method, this is no Problem because it handles both cases equally. The Problem occurs when you have a CR or a LF somewhere in the File that is not supposed to be there. This happens for example if you Export a

XML fragment with an ampersand

人盡茶涼 提交于 2019-12-13 04:16:45
问题 With a lot of help I worked out the following code: if (ofd.ShowDialog() == DialogResult.OK) { using (StreamReader reader = new StreamReader(ofd.FileName, Encoding.GetEncoding("ISO-8859-1"))) { XmlReaderSettings settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Fragment; using (XmlReader xreader = XmlReader.Create(reader, settings)) { while (xreader.Read()) { DoSomething(); } } } I have just one problem left and that is that there is an ampersand in some places

File sharing violation occurs after creation of file?

家住魔仙堡 提交于 2019-12-13 00:13:46
问题 So, I'm attempting to create a .txt file, and then write some silly data to it. But I'm getting a sharing violation. I sense that it may be because I'm attempting to create a StreamWriter for a file directly after creating it, but that doesn't make sense. So I'm a bit lost. I've tried removing all the other StreamWriters and Readers in the class except for the erroneous line, and I'm still getting a violation. The error I'm getting, IOException: Sharing violation on path C:\Users\USER\Desktop

Why am I getting a “NotSupportedException” with this code?

让人想犯罪 __ 提交于 2019-12-13 00:10:02
问题 I am trying to call a Web API method from a handheld device (Compact Framework) with this code: // "fullFilePath" is a value such as "\Program Files\Bla\abc.xml" // "uri" is something like "http://localhost:28642/api/ControllerName/PostArgsAndXMLFile?serialNum=8675309&siteNum=42" SendXMLFile(fullFilePath, uri, 500); . . . public static string SendXMLFile(string xmlFilepath, string uri, int timeout) { uri = uri.Replace('\\', '/'); if (!uri.StartsWith("/")) { uri = "/" + uri; } HttpWebRequest