Click here to Skip to main content
15,916,091 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
C#
Try
                Dim filePath As String
                filePath = System.IO.Path.Combine(
                           My.Computer.FileSystem.SpecialDirectories.Desktop, My.Forms.Form1.TXTNAME.Text)
                My.Computer.FileSystem.WriteAllText(filePath, My.Forms.Form1.TXTTEXT.Text, False)
            Catch fileException As Exception
                Throw fileException
            End Try


What I have tried:

I tried to mess around with some properties but none of them work. Instead it creates a File rather than a TXT File.
Posted
Updated 4-Apr-16 17:01pm
Comments
Sergey Alexandrovich Kryukov 4-Apr-16 23:55pm    
There are no such thing as "files versus txt file". A file is a file. "txt" is related to the file content, that's all.
—SA

1 solution

The TXT file as you call it is nothing more than a file extension. Unless you type a filename that ends in ".txt" into the TXTTEXT textbox, you're going to get the filename exactly as you typed it. The code will NOT add the .txt extension automatically. YOU have to supply that code.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 4-Apr-16 23:50pm    
I would add that, strictly speaking, there is no such thing as "extension", which used to exist in obsolete file system. Now, it's nothing but historical cultural convention, still cast in some API, notably in Windows Shell. The term "extension" is also in use. Technically, it's just an arbitrary part of file name, no difference from any other part of a simple name. Any name, any number of '.' characters, any order, anything, except characters prohibited to be in the file name...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900