How do I create a new folder using compact framework?

I am developing an app for the Pocket PC using VB.Net - compact framework. I need to know how to check if a folder exists. If it doesn't then create it.

Here is what I would like:


If \My Documents\Data\Folex does not exist then

create \My Documents\Data\Folex

End If


Thanks

PB
PBLackAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi PBLac;

This can create the directory if it does not exist

        Dim SourceDir As String = "c:\Documents and Settings\User\My Documents\Data\Folex"
        Dim source As DirectoryInfo = New DirectoryInfo(SourceDir)

        If Not source.Exists Then
            source.Create()
            Console.WriteLine("It exists")
        End If

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fernando SotoRetiredCommented:
That should be

        Dim SourceDir As String = "c:\Documents and Settings\User\My Documents\Data\Folex"
        Dim source As DirectoryInfo = New DirectoryInfo(SourceDir)

        If Not source.Exists Then
            source.Create()
        End If
PBLackAuthor Commented:
Hi

I am using VS 2003 VB.Net for compact framework. I am getting an error with your code.

Type 'DirectoryInfo' is not defined.

How do I fix this?

Thanks

PB
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Fernando SotoRetiredCommented:
Hi PBLack;

The DirectoryInfo Class is supported by the .NET Compact Framework, you need to

Imports System.IO

Pointer to documentation

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemiodirectoryinfomemberstopic.asp
PBLackAuthor Commented:
Hi

Thank you for your help. Got it now:

        Dim source As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(SourceDir)

        If Not source.Exists Then
            source.Create()
        End If

Cheers

PB
Fernando SotoRetiredCommented:
Yes you could do it that way but if you do not want to do so much typing you can do the following.

Imports System.IO      'Place this at the top of the code file

...

        Dim source As DirectoryInfo = New DirectoryInfo(SourceDir)

        If Not source.Exists Then
            source.Create()
        End If


Good Luck
Fernando
PBLackAuthor Commented:
Hi again

Yes I did that now to make it a little bit cleaner. Having come from the school of vba in msaccess apps the learning curve has been steep. But I am starting to like Vb.Net now.

Cheers

PB
Fernando SotoRetiredCommented:
Great, glad I could be of help to you. :-)

Fernando
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.