Need help with my code to create folder on Win 6 Mobile device using OpenNETCF RAPI

Hi

This is code that I am working on that is supposed to check to see if a couple of folders exist on a Windows Mobile 6 Device. If they do not exist then these folders will be created. Unfortunately it does not work and throws an error (see code below) but the error message provides me with nothing to go on. I've tried multiple web searches and have come up empty.

Please help.

Thanks

PBLack

     
Imports OpenNETCF.Desktop.Communication
---------------------------------------------------------------
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
       
            Dim strTallyDev As String = "\My Documents\Projects\Folder1"
            Dim strSetupdev As String = "\My Documents\Projects\Folder2"

            'check to see if project folders exists

            Dim directoryToListDev As String = "\My Documents\Projects\"
            'connect to device
            MyRapi = New RAPI
            MyRapi.Connect()

            Dim fileListDev As FileList = MyRapi.EnumFiles(directoryToListDev + "*"c)
            If fileListDev Is Nothing Then
                MyRapi.CreateDeviceDirectory(strTallyDev) 'Error thrown here - RAPIException was unhandled - Could not create directory
                MyRapi.CreateDeviceDirectory(strSetupdev)
            End If

            MyRapi.Disconnect()
            MyRapi.Dispose()
            MyRapi = Nothing
End Sub

Open in new window

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.

hjgodeCommented:
The problem is that you can not create a full path with multiple new dirs at once.

The other problem is that OpenNetCF.Desktop.Communication hides all the error details. Here is my addition to there code:
		public void CreateDeviceDirectory(string PathName)
		{
			CheckConnection();
			if(! Convert.ToBoolean(CeCreateDirectory(PathName, 0)))
			{
                int err = CeRapiGetError();
                int err2 = CeGetLastError();
                throw new RAPIException("Could not create directory: '" + PathName + "' RapiErr=" + err.ToString() + " ceErr=" + err2.ToString());
			}
		}

Open in new window


Now we see you will get CE error code 3L: ERROR_PATH_NOT_FOUND. And this lead me to the solution to split the path to the directory to create and use CreateDirectory on every part: A new function:

    Function makeFolder(ByVal p As String) As Boolean
        Dim result As Boolean = False
        Dim list As String()
        list = p.Split(New Char() {"\"c})

        Dim fullPath As String = "\"
        For ix As Integer = 0 To list.Length - 1
            If list(ix) <> "" Then
                fullPath += list(ix) + "\"
                Try
                    MyRapi.CreateDeviceDirectory(fullPath) 'error 187 already exists
                    result = True
                Catch ex As Exception
                    System.Diagnostics.Debug.WriteLine("exception in makePath: " + ex.Message)
                End Try
            End If
        Next

        makeFolder = result
    End Function

Open in new window


Here is your code changed using the new function:
Imports OpenNETCF.Desktop.Communication

Public Class Form1

    Dim MyRapi As OpenNETCF.Desktop.Communication.RAPI

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim strTallyDev As String = "\My Documents\Projects\Folder1"
        Dim strSetupdev As String = "\My Documents\Projects\Folder2"

        'check to see if project folders exists

        Dim directoryToListDev As String = "\My Documents\Projects\"
        'connect to device
        MyRapi = New RAPI
        MyRapi.Connect()

        Dim fileListDev As FileList = MyRapi.EnumFiles(directoryToListDev + "*"c)
        If fileListDev Is Nothing Then
            Dim bRes As Boolean
            bRes = makeFolder(strTallyDev)
            'MyRapi.CreateDeviceDirectory("\My Documents") 'error 187 already exists                
            'MyRapi.CreateDeviceDirectory("\My Documents\Projects") 'error 03 = ERROR_PATH_NOT_FOUND
            bRes = makeFolder(strSetupdev)
            'MyRapi.CreateDeviceDirectory(strTallyDev) 'Error thrown here - RAPIException was unhandled - Could not create directory
            'MyRapi.CreateDeviceDirectory(strSetupdev)
        End If

        MyRapi.Disconnect()
        MyRapi.Dispose()
        MyRapi = Nothing
    End Sub
    Function makeFolder(ByVal p As String) As Boolean
        Dim result As Boolean = False
        Dim list As String()
        list = p.Split(New Char() {"\"c})

        Dim fullPath As String = "\"
        For ix As Integer = 0 To list.Length - 1
            If list(ix) <> "" Then
                fullPath += list(ix) + "\"
                Try
                    MyRapi.CreateDeviceDirectory(fullPath) 'error 187 already exists
                    result = True
                Catch ex As Exception
                    System.Diagnostics.Debug.WriteLine("exception in malePath: " + ex.Message)
                End Try
            End If
        Next

        makeFolder = result
    End Function
End Class

Open in new window

0

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
PBLackAuthor Commented:
I discovered this last night and was just coming here to close the question and see that you found it too so full points. I was not aware that with RAPI that the DeviceFileExists argument applied to folders too. When I discovered that It was a breeze to code.

For example I used this:
                 If Not MyRapi.DeviceFileExists("\My Documents\Projects" Then
                    MyRapi.CreateDeviceDirectory("\My Documents\Projects\" & item.Text)
                End If

                If Not MyRapi.DeviceFileExists("\My Documents\Projects\" & item.Text) Then
                    MyRapi.CreateDeviceDirectory("\My Documents\Projects\" & item.Text)
                End If

Thank you for your effort.
0
PBLackAuthor Commented:
oops small typo now fixed:

For example I used this:
                 If Not MyRapi.DeviceFileExists("\My Documents\Projects" Then
                    MyRapi.CreateDeviceDirectory("\My Documents\Projects")
                End If

                If Not MyRapi.DeviceFileExists("\My Documents\Projects\" & item.Text) Then
                    MyRapi.CreateDeviceDirectory("\My Documents\Projects\" & item.Text)
                End If
0
hjgodeCommented:
Hopefully you will not try to execute that on a device with german or french OS language pack.

Thanks

Josef
0
PBLackAuthor Commented:
It is for English Only but good point. I never thought of that.
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.