Page 1 of 1

Save text to CSV file

Posted: 26 Mar 2016, 22:49
by Chris
Hi All,

I have created a basic form to collect some text and save it out in CSV format.
I'm not the best in the world at scripting......so would someone mind having a quick look over my scene and letting me know if I can improve the script
in any way??

Is this the most efficient way to create as CSV file in Ventuz?

I also wanted to force some rules for the text that is entered in the boxes, i.e. not allowing the text to be added to the file unless a valid email address is entered.
Would anyone know how I can accomplish this??

The scene is pretty basic at this point, but any other suggestions on the scene as a whole are also more than welcome :D

Thanks
Chris

Re: Save text to CSV file

Posted: 29 Mar 2016, 14:53
by joschy
may be you already found this: https://social.msdn.microsoft.com/Forum ... m=netfxbcl
I can't load your file currently, it's PLE. Don't know how large your file is and there is a for loop, you should use the thread class https://msdn.microsoft.com/en-us/librar ... 71%29.aspx

Re: Save text to CSV file

Posted: 29 Mar 2016, 21:59
by Chris
Hey,

Thanks for the reply joschy :)

Here's my code

Code: Select all

//if file doesnt exist, create file
		
		if (!File.Exists(filePath))
		{
			File.Create(filePath).Close();
		}
		
		// Append line to the file.
		
		using (StreamWriter writer = new StreamWriter(filePath, true))
		{
			writer.WriteLine(Data);
		}
       
		changed = true;
It all works fine, just wondering if there is anything I should change to make it better??

Cheers
Chris