What I need to do is create a file in memory, write to that file, and then access that file as you would with any other file.
Here I am creating and using an actual file:
if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "TEST.csv")))
{
File.Create(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "TEST.csv")).Dispose();
using (TextWriter tw = new StreamWriter(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "TEST.csv")))
{
foreach (string[] array in listOfRows)
{
string dataString = array[0] + "," + array[1] + "," + array[2] + "," + array[3];
tw.WriteLine(dataString);
}
tw.Close();
}
}
else if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "TEST.csv")))
{
using (TextWriter tw = new StreamWriter(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "TEST.csv")))
{
foreach (string[] array in listOfRows)
{
string dataString = array[0] + "," + array[1] + "," + array[2] + "," + array[3];
tw.WriteLine(dataString);
}
tw.Close();
}
}
//makes virtual table to be copied to database
DataTable dt = new DataTable();
string line = null;
int i = 0;
using (StreamReader sr = File.OpenText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "TEST.csv")))
{
//etc etc etc
}
So as you can see, currently I am just creating a file and then writing data to it, and then using that file. It would be much better for me if I could just do all this in virtual memory, is this possible?