I would like to copy the partial content of a file using FileStream
seek.
- the actual file stream length of the file =
98764
. - I want file content between length
200 and 5000
If I am doing
fileStream.Seek(200, SeekOrigin.Begin)
, then this give me file content from200 to 98764
, but I want from200 and 5000
.public static async Task<HttpResponseMessage> Get() { using (var fileStream = new FileStream(@"C:\test\tes1.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { var actualFileStremSize = fileStream.Length; //fileStream.Seek(200, SeekOrigin.Begin); var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(fileStream), }; using (FileStream fs = new FileStream(@"C:\test\tes1_partial_copy.txt", FileMode.CreateNew, FileAccess.Write)) { await result.Content.CopyToAsync(fs); } return result; } } }
Main Method,
class Program
{
static void Main(string[] args)
{
Get().Wait();
Console.ReadLine();
}
Looking for a solution to get file content between 2 file stream length. Thanks,