7 Replies - 338 Views - Last Post: 15 October 2013 - 04:08 AM Rate Topic: -----

#1 Bluezap  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 305
  • Joined: 19-January 12

Creating a txt file in My documents

Posted 13 October 2013 - 10:26 PM

HI , I use
Try
                Dim filePath As String
                filePath = System.IO.Path.Combine(
                           My.Computer.FileSystem.SpecialDirectories.MyDocuments, "textfile.txt")
                My.Computer.FileSystem.WriteAllText(filePath, textbox1.Text, False)
            Catch fileException As Exception
                Throw fileException
            End Try


to create a text file in the my documents folder. Is there anyway of creating a new folder inside My documents and creating the txt file in that?
for ex - \My documents\examplefolder\textfile.txt
Thanks! :)

Is This A Good Question/Topic? 0
  • +

Replies To: Creating a txt file in My documents

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4190
  • View blog
  • Posts: 11,864
  • Joined: 18-April 07

Re: Creating a txt file in My documents

Posted 13 October 2013 - 10:43 PM

Dim strPath As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "/somedir"

System.IO.Directory.CreateDirectory(strPath)
System.IO.File.CreateText(strPath & "/somefile.txt")



Just make sure you wrap the proper error handling around all this of course. Here we create the directory called "somedir" and then create "somefile.txt" inside of that. If you want to learn more, check out the Directory and File objects in the System.IO namespace.

:)
Was This Post Helpful? 3
  • +
  • -

#3 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2890
  • View blog
  • Posts: 9,597
  • Joined: 12-December 12

Re: Creating a txt file in My documents

Posted 14 October 2013 - 01:52 AM

Could use:

Dim strPath As String = System.IO.Path.Combine( _
    My.Computer.FileSystem.SpecialDirectories.MyDocuments, "somedir")

rather than "/".

This post has been edited by andrewsw: 14 October 2013 - 01:55 AM

Was This Post Helpful? 0
  • +
  • -

#4 Bluezap  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 305
  • Joined: 19-January 12

Re: Creating a txt file in My documents

Posted 14 October 2013 - 07:19 AM

Could you please see if this is the correct way to do this -
Try
                Dim filePath As String
                System.IO.Directory.CreateDirectory(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "/settings")
                filePath = System.IO.Path.Combine(
                           My.Computer.FileSystem.SpecialDirectories.MyDocuments & "/settings" & "/email.txt")
                My.Computer.FileSystem.WriteAllText(filePath, textbox1.Text, False)
            Catch fileException As Exception
                Throw fileException
            End Try


Thanks! :)
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2890
  • View blog
  • Posts: 9,597
  • Joined: 12-December 12

Re: Creating a txt file in My documents

Posted 14 October 2013 - 07:24 AM

Does it work? Does it give errors? That is the quickest way to find out if it works.

There is rarely one, correct way to create code: there are wrong ways, or more efficient ways ;)
Was This Post Helpful? 0
  • +
  • -

#6 Bluezap  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 305
  • Joined: 19-January 12

Re: Creating a txt file in My documents

Posted 14 October 2013 - 07:26 AM

Also is this the correct way in reading this info and displaying it?
 Dim fileReader As String
        fileReader = My.Computer.FileSystem.ReadAllText(System.IO.Path.Combine(
                           My.Computer.FileSystem.SpecialDirectories.MyDocuments & "/settings" & "/email.txt"))
        textbox1.Text = fileReader



View Postandrewsw, on 14 October 2013 - 07:24 AM, said:

Does it work? Does it give errors? That is the quickest way to find out if it works.

There is rarely one, correct way to create code: there are wrong ways, or more efficient ways ;)/>

It seems to be working fine, I was just wondering if this is the best way.
I have noticed that the application lags while performing this function, would it be ok to apply the code in a background worker?
Was This Post Helpful? 0
  • +
  • -

#7 Bluezap  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 305
  • Joined: 19-January 12

Re: Creating a txt file in My documents

Posted 15 October 2013 - 03:36 AM

Hi, are there any more suggestions to make the process faster?
Thank you.
Was This Post Helpful? 0
  • +
  • -

#8 HeBTeMy  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 299
  • Joined: 05-October 12

Re: Creating a txt file in My documents

Posted 15 October 2013 - 04:08 AM

View PostBluezap, on 15 October 2013 - 03:36 AM, said:

Hi, are there any more suggestions to make the process faster?
Thank you.


In what way do you want it to be faster? Creating a folder with a txt inside ? lol
That wouldn't take more than 0.5s... ?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1