Getting an embedded resource
I'm stuck on this one...
I've figured out how to get an embedded picture file to be referenced (and that successfully shows a pic in a control, depending on another item being clicked). That works fine, got loads of pics sorted. What I can't figure out is how to read an embedded text file, process it, and throw the data in to an array.
Code:
public ResourceManager pics128Ships = new ResourceManager("POS_and_Fuel_Calculator.128shipPics", Assembly.GetExecutingAssembly());
public ResourceManager pics128Pos = new ResourceManager("POS_and_Fuel_Calculator.128posPics", Assembly.GetExecutingAssembly());
public ResourceManager pics256Pos = new ResourceManager("POS_and_Fuel_Calculator.256Pics", Assembly.GetExecutingAssembly());
public ResourceManager DataPOSShips = new ResourceManager("POS_and_Fuel_Calculator.POSandShipsData", Assembly.GetExecutingAssembly());
the first three are pictures, no problems with those, so I should expect to do the same with the last one, which calls the *.resx file that has the information about the text files.
However, I'm not sure if I should be using the streamreader method to read through the text files, as building the program is fine, but running/debugging it produces -
Code:
System.ArgumentNullException was unhandled
Message="Value cannot be null.\r\nParameter name: path"
Source="mscorlib"
ParamName="path"
StackTrace:
at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
at System.IO.StreamReader..ctor(String path)
at POS_and_Fuel_Calculator.Form1.Form1_Load(Object sender, EventArgs e) in K:\Programming Projects\POS and Fuel Calculator\POS and Fuel Calculator\Form1.cs:line 43
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at POS_and_Fuel_Calculator.Program.Main() in K:\Programming Projects\POS and Fuel Calculator\POS and Fuel Calculator\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
The error originates from the first line here - (which is pretty much the first line of code in the whole program)
Code:
StreamReader sr = new StreamReader(DataPOSShips.GetString("Ships.db"));
//StreamReader sr = new StreamReader(@"K:\Programming Projects\POS and Fuel Calculator\POS and Fuel Calculator\POS.db"); //the old way of calling a file (it worked...)
StringBuilder sb = new StringBuilder("");
int stringCounter = 0;
while (fuelSize != -1)
{
char char1 = (char)sr.Read();
string string1 = char1.ToString();
if (string1 == "#")
{
shipsList[stringCounter] += sb.ToString(0, sb.Length);
break;
}
if (string1 == "@")
{
shipsList[stringCounter] += sb.ToString(0, sb.Length);
sb.Remove(0, sb.Length);
stringCounter++;
}
else
{
sb.Append(string1);
}
}
What should I be doing to read in this damn text file??