Skip to main content
Contributor
Oct 24, 2024 7:20 PM UTC
Solved

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!

Contributor
Oct 31, 2024 9:52 PM UTC

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!


Glad to hear it & thanks for sharing your solution for others.

6 replies

Veteran
Oct 24, 2024 7:39 PM UTC

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
Contributor
Oct 24, 2024 8:21 PM UTC

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.

Contributor
Oct 24, 2024 11:24 PM UTC

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
Contributor
Oct 30, 2024 7:30 PM UTC

I'll check it out, thanks!

cap08Author
Contributor
Oct 31, 2024 12:22 PM UTC

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!