troubleshooting Question

Reading in an Embedded text file C#:

Avatar of revis
revis asked on
C#
6 Comments1 Solution320 ViewsLast Modified:
In the following code I'm getting a run time error because s remains undefined. What am I doing wrong here? I need to read in an embedded text file from my Solution Explorer. Error occurs at  b = new byte[System.Convert.ToInt32(s.Length)]; because s is undefined.

using System;
using System.Globalization;
using System.Threading;
using System.IO;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Reflection;

public TermForm()
{
   //
   // Required for Windows Form Designer support
  //

   InitializeComponent();

   Stream s;
   byte[] b;

   // Get default script source from embedded text file
   s = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsApplication1.defaultscript.txt");
   b = new byte[System.Convert.ToInt32(s.Length)];
   s.Read(b, 0, System.Convert.ToInt32(s.Length));
   ScriptSource = System.Text.ASCIIEncoding.ASCII.GetString(b);
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros