Hello Ventuzians!
THE FORUMS ARE CLOSED!

Please join our discord server HERE!! << click me :D

We are shutting our Ventuz Forum, but don't worry, it will all be archived for you to search in if you have a query. From now on, please add all your comments, questions or observations into our Discord Server

Thanks for the great time - see you on discord!!
Dee, Karol, Daniel and the whoooole Product and Support team!

C# write a text file

Q and A about functionality and how to solve a special task for your application.

Moderator: Support

Post Reply
VincentPix
Posts: 48
Joined: 06 Nov 2014, 15:07

C# write a text file

Post by VincentPix » 07 Oct 2015, 11:26

Hello,

I'm trying to script a writer node.

a string Input (my text)
a string URL
and a Method write

also add using System.IO

Code: Select all

// This Method is called if the function/method Write is invoked by the user or a bound event.
	// Return true, if this component has to be revalidated!
	public bool OnWrite(int arg)
	{
		StreamWriter writetext = new StreamWriter(URL);
		writetext.WriteLine(Input);
		writetext.Close();
		
		changed = true;
		return false;
	}
I've also tried this method : File.WriteAllText(path, createText);

None gave a result.

Does someone have an idea ?

Thanks

User avatar
lerou
Posts: 345
Joined: 06 Sep 2013, 07:14
Location: Hamburg, Germany

Re: C# write a text file

Post by lerou » 07 Oct 2015, 11:31

Don't know what your URL ist. I've used this just recently where the input was a relative path like './log.txt':

Code: Select all

private void Log(string s)
{
	try
	{
		using (StreamWriter w = File.AppendText(inLogFile))
		{
			var now = DateTime.Now;
			w.WriteLine(string.Format("{0},{1}", now, s));
		}
	}
	catch
	{
	}
}

VincentPix
Posts: 48
Joined: 06 Nov 2014, 15:07

Re: C# write a text file

Post by VincentPix » 07 Oct 2015, 11:48

Thanks Lerou,

the URL is the full path as a string "‪D:\VENTUZ\V4tests\Data\MaConfig.txt"

I should have missed something cause I can't have your code working either. (ashamed)

TVM Cracklings
Posts: 33
Joined: 30 Sep 2015, 10:49

Re: C# write a text file

Post by TVM Cracklings » 07 Oct 2015, 16:07

Don't forget to escape the backslash in the path string, or replace it with a normal slash.

User avatar
lerou
Posts: 345
Joined: 06 Sep 2013, 07:14
Location: Hamburg, Germany

Re: C# write a text file

Post by lerou » 07 Oct 2015, 16:28

he's putting in the string as a parameter so he doesn't need escaping it. Also in C# you'd use @"..."

VincentPix
Posts: 48
Joined: 06 Nov 2014, 15:07

Re: C# write a text file

Post by VincentPix » 07 Oct 2015, 16:46

It's working perfectly !

Great tool with the json parser.

Thank you

Post Reply