Hello all. I have not had to create folderitems until now, so I am definitely missing experience with this. I have a small piece of method that creates one. The folderitem is created (not nil) but the test for folderitem.exists fails. What am I missing?
Var F as folderitem
Var fdest as string = App.ExecutableFile.Parent.NativePath + "UploadedDocuments\" + FN
F = New folderitem (FDest, FolderItem.PathModes.Native)
If F <> Nil and F.exists Then
t = TextOutputStream.Open(F)
t.Write(outputstr)
t.Close
End If
Here, FN is equal to “test.pdf”. The folderitem is not nil, I can seee all its properties in the debug pane. If I only test for F<> Nil, I get an IOException 3 (“path not found” on Windows). If I test as shown, I just skip the writing part. What am I missing that causes F to not exist?
The path is S:\Software\Geoff\2024 R3\UploadedDocuments. It exists and is open to write for all users. The user running the program has admin rights too.
I tried that originally. app.executablefile.parent.nativepath does show "" for me on Windows 11. I had double \ before uploadeddocuments when I tried that.
When I start a new project involving file access I always keep a small DesktopTextArea handy where I log certain things with automatic scroling…
ConsoleArea.AddText(s)
var amountOfLineNumbers as integer = ConsoleArea.LineNumber( ConsoleArea.Text.Length )
for i as integer = 0 to amountOfLineNumbers
ConsoleArea.VerticalScrollPosition = i
next
Can you set a Label text to “fdest” ?
Then you see where it tries to access the file…
You should try to avoid converting FolderItems to path strings, manipulating them and then converting back to FolderItems.
This should work better:
Var F as folderitem
F = App.ExecutableFile
If F <> Nil Then
F = F.Parent
If F <> Nil Then
F = F.Child("UploadedDocuments")
If F <> Nil Then
F = F.Child(FN)
End If
End If
End If
If F <> Nil Then
t = TextOutputStream.Open(F)
t.Write(outputstr)
t.Close
End If
(the above code that builds F could be simplified if you used exceptions).
Var F as folderitem
'Var fdest as string = App.ExecutableFile.Parent.NativePath + "UploadedDocuments\" + FN
'F = New folderitem (FDest, FolderItem.PathModes.Native)
F = App.ExecutableFile.Parent
If F <> Nil Then
F = F.Child("UploadedDocuments")
If F <> Nil Then
F = F.Child(FN)
End If
End If
If F <> Nil and F.exists Then
t = TextOutputStream.Open(F)
t.Write(outputstr)
t.Close
End If