Skip to main content
October 24, 2024
Solved

Conversion from string to type integer is not valid

  • October 24, 2024
  • 3 replies
  • 0 views

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!

Best answer by DanielWillis

I think you might be using DeleteFile wrong.

DanielWillis_0-1729812069852.png

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.

 

3 replies

October 24, 2024

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

 

 

cap08Author
October 24, 2024

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.

October 24, 2024

I think you might be using DeleteFile wrong.

DanielWillis_0-1729812069852.png

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.

 

cap08Author
October 30, 2024

I'll check it out, thanks!

cap08Author
October 31, 2024

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!