Forums
New posts
Search forums
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
VB.NET Community
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
C#
Windows Forms
Creating Form1 txt file, to use in Form2 (HangMan)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="jmcilhinney, post: 25645, member: 3"] You certainly should not be using files to communicate between forms in the same application. Forms are objects, so you get data into and out of them in exactly the same way as you do any other objects. You should read [URL='http://jmcilhinney.blogspot.com/2012/04/managing-data-among-multiple-forms-part.html']this[/URL]. There are three parts, so read all three. The last is the most important but the first two are good for background. That aside, your original code makes little sense. You seem very keen on [ICODE]Path.Combine[/ICODE] with no understanding of how it works. The whole point is to combine multiple partial paths into a single full path. Both here: [CODE=csharp]File.WriteAllText(Path.Combine("log.txt"), txt_firstname.Text + " " + textBox2.Text);[/CODE] and here: [CODE=csharp]target = Path.Combine(Directory.GetCurrentDirectory());[/CODE] you are only passing one partial path to the method, so you get out exactly what you get in. If the idea is to get a file path by combining a folder path and a file name then you need to provide both the folder path and the file name, e.g. [CODE=csharp]Path.Combine(Directory.GetCurrentDirectory(), "log.txt")[/CODE] That said, you almost certainly should not be using the current directory. That will generally be the folder the application was run from but it won't always be and it can change while the application is running. If what you want is the path of the folder that the application was run from then you should be using [ICODE]Application.StartupPath[/ICODE] in a WinForms app. That said, if you have deployed to the [I]Program Files[/I] folder then the startup folder will likely be read-only. Windows provides multiple special folders that are intended for applications to write data to so use them. Some of their paths can be accessed using [ICODE]Environment.GetFolderPath[/ICODE], e.g. [CODE=csharp]var filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), fileName);[/CODE] If the file will be short-lived then you might even use a dedicated temp file, although they will have a random name. [/QUOTE]
Insert quotes…
Verification
Post reply
C#
Windows Forms
Creating Form1 txt file, to use in Form2 (HangMan)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top
Bottom