Cannot detach files using script

I know I’ve done this before, but for some reason it’s not working this time. I’m sure it must be something simple I’m overlooking. Please assist.

Trying to detach files from selected documents in a view to a local drive. This script is behind a view action button:

Dim s As New NotesSession

Dim db As NotesDatabase

Dim coll As notesdocumentcollection

Dim doc As NotesDocument

Dim rtitem As Variant

Set db = s.CurrentDatabase

Set coll = db.UnprocessedDocuments

For j = 1 To coll.Count

Set doc = coll.GetNthDocument(j)

Set rtitem = doc.GetFirstItem( “PrintDocument” )

If ( rtitem.Type = RICHTEXT ) Then

Forall o In rtitem.EmbeddedObjects

  If ( o.Type = EMBED_ATTACHMENT ) Then

    filepath$ = "C:\Forms\" & doc.GetFirstItem("Category").text & "\" & o.Name()

    Call o.ExtractFile (filepath$)			

  End If

End Forall

End If

Next

The error I get is Notes Error: File Cannot Be Created (file path and name are displayed here)

Any help will be greatly appreciated.

Thanks!

Subject: Cannot detach files using script

Do the paths for each category exist ? If not, they need to be created before it will let you create the file. It won’t automatically create the directory structure for you, so you need to do this yourself.

e.g.

If Dir("C:\Forms" & doc.GetFirstItem(“Category”).text, 16) = “” Then

MkDir("C:\Forms\" & doc.GetFirstItem("Category").text)

End If

Subject: Another alternative

Have a look at FileSystemObject and the various methods and properties it provides.

The problem could be the wrong file path or inappropriate access to folder.

–Phani

Subject: RE: Cannot detach files using script

That’s what it was. Wow, I guess I assumed too much on that method! Thanks for the reminder :slight_smile:

Subject: Cannot detach files using script

Normally when that message pops up on me it’s because there’s a character in the filename that shouldn’t be there. an * or a \ . Make sure the file name is basic letters and test your agent again.