Skip to main content

All Questions

0 votes
0 answers
36 views

Does a MailMessage Attached to a Stream Generate a File?

In one method I have the below code: var newMessage = new MailMessage(); newMessage.Attachments.Add(new Attachment(ToStream("testAttachment"), MediaTypeNames.Text.Plain)); Then I have this ...
user98's user avatar
  • 17
3 votes
2 answers
463 views

In C#, using "using" results in errors, is there a better practice than just not using "using"?

I have the following method: [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "If we dispose of the csvWriter, it won't be ...
Brian Kessler's user avatar
1 vote
0 answers
1k views

Getting error when saving a file: Cannot access a closed Stream

I have a sitemap writer file which creates sitemap: public class SitemapWriter : IDisposable { public MemoryStream _outputStream; public StreamWriter _outputWriter; public SitemapWriter() ...
Hooman Bahreini's user avatar
0 votes
1 answer
1k views

Empty File Created without text in .txt file in .NET Core

[HttpPost] public FileResult DownloadFile(int id) { using (MemoryStream ms = new MemoryStream()) { var sw = new StreamWriter(ms); sw.Write("Hi"); ...
CoderGuy's user avatar
3 votes
1 answer
7k views

ZipArchive InvalidDataException: End of Central Directory record could not be found

I am getting the following InvalidDataException thrown when opening an archive made up from a FormFile. System.IO.InvalidDataException: 'End of Central Directory record could not be found.' at ...
Dave New's user avatar
  • 39.6k
1 vote
0 answers
274 views

Is there any relation between stream & streamreader/streamwriter & string in c#? [duplicate]

I have a library that uses StreamWriter to write a string into a Stream. I need it to write that string into a NOT FILE stream like MemoryStream. But when I try to read from that MemoryStream using a ...
Kamran Kia's user avatar
1 vote
1 answer
2k views

Return stream immediately and then write to stream asynchronously

In my current code I have a method like this to read data from a device (pseudo code): public async Task<string> ReadAllDataFromDevice() { var buffer = ""; using (var device = new ...
Robert Hegner's user avatar
0 votes
2 answers
1k views

C# Memorystream is not fully saved to the file

I am exporting an object to csv using MemoryStream and StreamWriter. But after saving the file, I see that the end of the file is missing. Its cut of in the middle of a line. Below is my code: ...
Mivaweb's user avatar
  • 5,690
0 votes
2 answers
1k views

Creating XML Document with StreamWriter from DB

So I got requested to have the option to download/create an XML file from a Database. The table contains a column with the raw XML message in it. User needs to be able to save the XML Doc for viewing. ...
Flipoff94's user avatar
1 vote
1 answer
9k views

MemoryStream output to a file c#

I have below code: string fileName = GetFileName(); using (var stream = new MemoryStream()) { using (var sw = new StreamWriter(stream)) { for (int i = 0; i < 20; i++) ...
Willy's user avatar
  • 10.4k
0 votes
1 answer
2k views

Trying to send csv as an email attachment in C#

When I use StreamWriter.WriteLine it doesn't seem to write anything to a MemoryStream. -"data" is something that is previously populated. It is an object[] that includes objects that have Name, Date, ...
clueless7788's user avatar
34 votes
1 answer
14k views

Does a Stream get Disposed when returning a File from an Action? [duplicate]

I'm writing a string to a MemoryStream I need to return the stream to the Controller Action so I can send it off as a file for download. Normally, I wrap the Stream in a using statement, but, in ...
John-Luke Laue's user avatar
3 votes
0 answers
73 views

Few last lines missing in CSV downloaded [duplicate]

I am using HttpResponse.BinaryWrite to create a download a csv file. But I am always getting some last lines missing in csv downloaded. Below I have mentioned my code. I tried by adding bufferSize in ...
prashant's user avatar
  • 471
1 vote
4 answers
671 views

Why does StreamWriter need to be open to access my MemoryStream?

I have some test code that's preparing a MemoryStream that will eventually be read by an object. Here's how I want to write it: var manager = new LeaderboardImportManager(leaderboard); ...
Samo's user avatar
  • 8,210
1 vote
1 answer
2k views

c#: Getting line count from MemoryStream/StreamWriter

I use the following code to write log file: Encoding enc = Encoding.GetEncoding(932); MemoryStream msLog = new MemoryStream(); StreamWriter swLog = new StreamWriter(msLog, enc); swLog.WriteLine("Line ...
synergetic's user avatar
  • 7,986

15 30 50 per page