Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C#]TextWriter.Write fails

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Mon Feb 23, 2009 5:20 am    Post subject: [C#]TextWriter.Write fails Reply with quote

Ok, I'm having a file that I want to write some information to, but whenever I try to write to it with a string containing a filepath, the operation fails. Why is this? Any help is greatly appreciated.
Edit: Typo in title.

_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren
Back to top
View user's profile Send private message MSN Messenger
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Mon Feb 23, 2009 7:44 am    Post subject: Reply with quote

Details? Code? Errors?
Roll fucking eyes. Rolling Eyes

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Mon Feb 23, 2009 7:50 am    Post subject: Reply with quote

There is no error, the text is simply not written to the file. I didn't think the code would be needed considering the only interesting part is the call itself:
Code:
StreamWriter someStream = new TextWriter(filename);
someStream.Write(theStringToWrite);

_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren
Back to top
View user's profile Send private message MSN Messenger
iNoobHacker
Advanced Cheater
Reputation: 0

Joined: 05 Nov 2006
Posts: 99

PostPosted: Mon Feb 23, 2009 7:58 am    Post subject: Reply with quote

Close the file...
Back to top
View user's profile Send private message
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Mon Feb 23, 2009 8:02 am    Post subject: Reply with quote

I'm sorry if I mislead you, the code is actually like this :
Code:
using(StreamWriter someStream = new TextWriter(filename))
{
someStream.Write(theStringToWrite);
}

Now correct me if I'm wrong, but doesn't this automatically close the stream after the closing bracket?
Edit: Typo.

_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren


Last edited by Odecey on Mon Feb 23, 2009 8:14 am; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
iNoobHacker
Advanced Cheater
Reputation: 0

Joined: 05 Nov 2006
Posts: 99

PostPosted: Mon Feb 23, 2009 8:09 am    Post subject: Reply with quote

The object will be disposed but the Close method will not be called automatically, I belive.
Back to top
View user's profile Send private message
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Mon Feb 23, 2009 8:12 am    Post subject: Reply with quote

Adding someStream.Close(); did not have any effect on the programs behaviour that I could see. I suspected this, considering it works fine when saving strings that does not contain filepaths.
Edit: Made a workaround for it. A part of the problem seems to have been that the default directory changes when using FileDialogs.

_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren
Back to top
View user's profile Send private message MSN Messenger
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Tue Feb 24, 2009 5:36 am    Post subject: Reply with quote

Odecey wrote:
There is no error, the text is simply not written to the file. I didn't think the code would be needed considering the only interesting part is the call itself:
Code:
StreamWriter someStream = new TextWriter(filename);
someStream.Write(theStringToWrite);

TextWriter is abstract you should get an error with that code.

iNoobHacker wrote:
The object will be disposed but the Close method will not be called automatically, I belive.

When you use 'using' it will be closed automatically.


You can create a new instance of a streamwriter and write to the file.

Code:
using (StreamWriter someStream = new StreamWriter(@"C:\test\lol.txt"))
  {
    someStream.Write("hijax");
  }


That will erase the file whenever it attempts to write to the file tho, if you want to append just send a bool like this :
Code:
using (StreamWriter someStream = new StreamWriter(@"C:\test\lol.txt", true))
            {
                someStream.Write("jihad");
            }

_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites