[Solved] Why does this code hang on reaching the first ReadLine from a StreamReader?

I think you should return to basics: public static string SendXMLFile(string xmlFilepath, string uri, int timeout) { using (var client = new WebClient()) { client.Headers.Add(“Content-Type”, “application/xml”); byte[] response = client.UploadFile(uri, “POST”, xmlFilepath); return Encoding.ASCII.GetString(response); } } and see what works and what the server thinks of your file. When you really need a TimeOut then … Read more

[Solved] Replacing a certain word in a text file

If you don’t care about memory usage: string fileName = @”C:\Users\Greg\Desktop\Programming Files\story.txt”; File.WriteAllText(fileName, File.ReadAllText(fileName).Replace(“tea”, “cabbage”)); If you have a multi-line file that doesn’t randomly split words at the end of the line, you could modify one line at a time in a more memory-friendly way: // Open a stream for the source file using (var … Read more

[Solved] Streamreader locks file

StreamReader smsmessage = new StreamReader(filePath); try { FileInfo filenameinfo = new FileInfo(filePath); …. smsmessage = filenameinfo.OpenText(); … You are initializing smsmessage twice, but only disposing one of those instances. The first line constructs a StreamReader, and then you overwrite your reference to that instance with the instance created by filenameinfo.OpenText(). That leaves you with an … Read more