filestream

How to read character in a file 1 by 1 c#

亡梦爱人 提交于 2019-11-30 04:45:20
问题 I want my program to read a text file all characters 1 by 1 and whereever it finds inverted comma ( " ), it adds a semicolon before that inverted comma. For eg we have a paragraph in a text file as follow: This is a paragraph which conains lots and lots of characters and some names and dates. My name "Sam" i was born at "12:00" "noon". I live in "anyplace" . Now i want the output to be as follows : This is a paragraph which conains lots and lots of characters and some names and dates. My name

JPEG data-stream to TImage

。_饼干妹妹 提交于 2019-11-30 03:15:16
问题 I have some image-files stored into one file (some kind of archive). That file looks like this: Well, it's separated into two segments - header and data-segment. Header (green) contains various info, such as album name, location, date/time, description, number of photos in the album, etc. Data segment (blue & orange) has simple structure and it contains N x JPEG photo. I can extract that "imagedata" segment into new TMemoryStream object and now I want to show it using TImage. I can use

Http MultipartFormDataContent

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 01:46:43
问题 I have been asked to do the following in C#: /** * 1. Create a MultipartPostMethod * 2. Construct the web URL to connect to the SDP Server * 3. Add the filename to be attached as a parameter to the MultipartPostMethod with parameter name "filename" * 4. Execute the MultipartPostMethod * 5. Receive and process the response as required * / I have written some code that has no errors, however, the file is not attached. Can someone have a look at my C# code to see if I have written the code

Caching a binary file in C#

核能气质少年 提交于 2019-11-29 20:58:39
问题 Is it possible to cache a binary file in .NET and do normal file operations on cached file? 回答1: The way to do this is to read the entire contents from the FileStream into a MemoryStream object, and then use this object for I/O later on. Both types inherit from Stream , so the usage will be effectively identical. Here's an example: private MemoryStream cachedStream; public void CacheFile(string fileName) { cachedStream = new MemoryStream(File.ReadAllBytes(fileName)); } So just call the

Handling with temporary file stream

微笑、不失礼 提交于 2019-11-29 20:10:02
问题 Say I want to define a TempFileStream class that creates a temporary file using Path.GetTempFileName() method. A temporary file must be deleted when TempFileStream's object is no longer needed, e.g. closed or disposed: class TempFileStream: FileStream { string m_TempFileName = Path.GetTempFileName(); public TempFileStream(FileMode fileMode): base(m_TempFileName,fileMode) {} /// ... public ovverride Dispose(bool disposing) { /// ??? } } How should I implement this simply and safely? 回答1: Try

FileStream vs/differences StreamWriter?

試著忘記壹切 提交于 2019-11-29 19:14:05
Question: What is different between FileStream and StreamWriter in dotnet? What context are you supposed to use it? What is their advantage and disadvantage? Is it possible to combine these two into one? What is different between FileStream and StreamWriter in dotnet? A FileStream is a Stream . Like all Streams it only deals with byte[] data. A StreamWriter : TextWriter , is a Stream-decorator. A TextWriter encodes Text data like string or char to byte[] and then writes it to the linked Stream . What context are you supposed to use it? What is their advantage and disadvantage? You use a bare

Example of Why stream::good is Wrong?

只谈情不闲聊 提交于 2019-11-29 17:45:45
问题 I gave an answer which I wanted to check the validity of stream each time through a loop here. My original code used good and looked similar to this: ifstream foo("foo.txt"); while (foo.good()){ string bar; getline(foo, bar); cout << bar << endl; } I was immediately pointed here and told to never test good . Clearly this is something I haven't understood but I want to be doing my file I/O correctly. I tested my code out with several examples and couldn't make the good -testing code fail.

How can I get uploaded file full path in C# 3.0?

允我心安 提交于 2019-11-29 17:40:22
In my ASP.NET MVC website, I have to read a txt file with some names and emails separeted by ';'. After that, I have to save each line of this txt file to database. Googling around, I've found some snippets, but in all of them I have to use the txt file path. But, how can I get this path? This file could be anywhere in a user's machine! Thanks!! You cannot get the full path of an uploaded file. This would be a privacy violation for the user that uploaded the file. Instead, you'll need to read the Request.Files that have been uploaded. For example: HttpPostedFile file = Request.Files[0]; using

Why does Code Analysis tell me, “Do not dispose objects multiple times” here:

允我心安 提交于 2019-11-29 16:34:47
On this code: public static string Base64FromFileName(string fileName) { try { FileInfo fInfo = new FileInfo(fileName); long numBytes = fInfo.Length; FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fStream); byte[] bdata = br.ReadBytes((int)numBytes); br.Close(); fStream.Close(); return Convert.ToBase64String(bdata); } catch(Exception e) { throw e; } } ...I get, courtesy of Visual Studio's Code Analysis tool, the warning, " Do not dispose objects multiple times...To avoid generating a System.ObjectDisposedException you should

How to expose a sub section of my stream to a user

眉间皱痕 提交于 2019-11-29 14:14:49
I have a stream that contains many pieces of data. I want to expose just a piece of that data in another stream. The piece of data I want to extract can often be over 100mb. Since I already have stream with the data in it it seems like a waste to copy that data to another stream and return that. What im looking for is a way to reference the data in the first stream while controlling how much of it the second stream can reference. Is this possible There is a good implementation of this by Mark Gravell detailed here . The code posted there is: using System.IO; using System; static class Program