Forum Discussion

cap08's avatar
cap08
New Contributor III
3 months ago

Conversion from string to type integer is not valid

Hello, 

I'm trying to delete a File Share file but getting the error in the Subject above and I don't know what's causing it - I'm hoping someone can help. 

This is my code:

Dim fileName As String = "MyFile.csv"

Dim folderPath As String = BRApi.FileSystem.GetFileShareFolder(si, FileShareFolderTypes.ApplicationRoot, api) + "\" + si.AppName + "\Groups\MyFolder

BRApi.FileSystem.DeleteFile(si, folderPath, fileName)

When this runs, this is the error:  "Conversion from string "\\sgc000462adev2.file.core.windo" to type 'Integer' is not valid." 

Why is it trying to convert the folderPath to Int?  How do I fix this?

Thanks in advance for your help!

  • I think you might be using DeleteFile wrong.

    I don't think it is expecting a string path in the 2nd parameter, it is expecting a FileSystemLocationType, e.g., FileSystemLocation.FileShare or FileSystemLocation.ApplicationDatabase. If there was a path I believe it would go into the fileFullName parameter.

     

  • DanielWillis's avatar
    DanielWillis
    Valued Contributor

    I think you might be using DeleteFile wrong.

    I don't think it is expecting a string path in the 2nd parameter, it is expecting a FileSystemLocationType, e.g., FileSystemLocation.FileShare or FileSystemLocation.ApplicationDatabase. If there was a path I believe it would go into the fileFullName parameter.

     

    • cap08's avatar
      cap08
      New Contributor III

      I'll check it out, thanks!

      • cap08's avatar
        cap08
        New Contributor III

        Hi DanielWillis

        Your suggestion made things clearer for me and I found a Snippet (the Snippets are great!) so my solution was:

        Dim filePath As String = path.Combine(extractFolderPath.ToString,fileName)

        'if file exists, delete it
        If system.IO.File.Exists(filePath) Then
        System.IO.File.Delete(filePath)
        End If

        So simple!

        Thanks so much!

  • Hi,

    Try Path.Combine please 

    Dim folderPath As String = System.IO.Path.Combine(BRApi.FileSystem.GetFileShareFolder(si, FileShareFolderTypes.ApplicationRoot, api), si.AppName, "Groups", "MyFolder")

     

    Thanks,

    Nidhi

     

     

  • cap08's avatar
    cap08
    New Contributor III

    HI Nidhi

    I tried your suggestion (which is much easier to read), but it failed with the same error. This is my modified code:

    Dim folderPath As String = System.IO.Path.Combine(BRApi.FileSystem.GetFileShareFolder(si, FileShareFolderTypes.ApplicationRoot, api), si.AppName, "Groups", "MyFolder")

    BRApi.FileSystem.DeleteFile(si, folderPath, fileName)

    It fails on the delete statement but if I comment it out and run again, there's no issue with the subsequent writecsv statement. 

    writecsv(dt, path.Combine(folderPath,fileName))

    I don't understand why one fails and the other doesn't.