All Questions
Tagged with streamwriter memorystream
31
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 ...
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 ...
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()
...
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");
...
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
...
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 ...
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 ...
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:
...
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. ...
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++)
...
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, ...
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 ...
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 ...
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);
...
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 ...