Results 1 to 6 of 6

Thread: [RESOLVED] Why I can't create Folder on Desktop by VB

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    76

    Resolved [RESOLVED] Why I can't create Folder on Desktop by VB

    I don't know what went wrong, but I am not able to create a folder using the following code

    Code:
    My.Computer.FileSystem.CreateDirectory(Environ("%UserProfile%") & "\Desktop\abc")
    Last edited by riteshtechie; Jan 10th, 2010 at 06:43 AM.
    < advertising link removed by moderator >

  2. #2
    Addicted Member
    Join Date
    Sep 2008
    Posts
    149

    Re: Why I can't create Folder on Desktop by VB

    You should write full path to directory. Here is simple code:
    Code:
    Dim strUser As String
            strUser = Environment.UserName
            My.Computer.FileSystem.CreateDirectory("C:\Documents and Settings\" & strUser & "\Desktop\abc")

  3. #3
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Why I can't create Folder on Desktop by VB

    How about

    Code:
    My.Computer.FileSystem.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\abc")

  4. #4
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Why I can't create Folder on Desktop by VB

    Quote Originally Posted by Blagojce View Post
    You should write full path to directory. Here is simple code:
    Code:
    Dim strUser As String
            strUser = Environment.UserName
            My.Computer.FileSystem.CreateDirectory("C:\Documents and Settings\" & strUser & "\Desktop\abc")
    No No No No No!

    Use the proper facilites provided by .Net.

    What if someone is not using an English language version of Windows where "Documents and Settings" is called something totaly different? Or if documents and settings isn't on the C: drive?
    Last edited by keystone_paul; Jan 10th, 2010 at 06:44 AM.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    76

    Re: Why I can't create Folder on Desktop by VB

    Thanks KeyStone andBlagojce for helping me out
    < advertising link removed by moderator >

  6. #6
    Addicted Member
    Join Date
    Sep 2008
    Posts
    149

    Re: Why I can't create Folder on Desktop by VB

    Yes keystone_paul, you're right.
    I would have it in mind.

    riteshtechie don't forget mark topic as resolved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width