0

Good Day,

I am reading some files (Crystal Report files) that are stored as embedded resources, and have the following code to do so:

string[] listOfFiles = Assembly.GetExecutingAssembly().GetManifestResourceNames();
string applicationPath = @"C:\TEMP\Reports";
foreach (string item in listOfFiles)
{
    string fileName = item.Replace("RegistryReader.Reports.", String.Empty);
    Stream inputStream = GetEmbeddedResourceStream(item);
    string report = Path.Combine(applicationPath, fileName);
    using (StreamWriter sw = new StreamWriter(report))
    {
        sw.Write(inputStream);
        sw.Flush();
    }
}

The following code appears to work and when I'm in debug mode, I can see that the length of the inputStream is the correct number of bytes, unfortunately, it only writes 31 bytes for each file.

Am I missing something? Or should I be using a binary writer.

coson
  • 8,301
  • 15
  • 59
  • 84
  • Yes, you are copying a byte stream. Check this question for a full discussion [Write file from assembly resource stream to disk](http://stackoverflow.com/questions/864140/write-file-from-assembly-resource-stream-to-disk) – Phill Tew Jan 24 '12 at 22:23
  • You are writing the stream *object*, not the stream *content*. Stream.CopyTo() in .NET 4 – Hans Passant Jan 24 '12 at 22:28
  • @RugCode thanks for the heads up. I'm using your suggestion. – coson Jan 25 '12 at 00:31
  • @Hans - you're soooooooo right, thank you. Can't use the CopyTo() method as I'm not using .NET 4. – coson Jan 25 '12 at 00:31

0 Answers0