Search code examples
vb.netsmartsheet-api

Smartsheet API Attachement


I am having a problem with the attachemnt in the smartsheet API.

It keeps telling me that the file path format is not supported at this line

smartSheet.SheetResources.RowResources.AttachmentResources.AttachFile(id, 1, "N:\TEST\M-TST-12346\M-TST-12346-TV.pdf", "application/pdf")

Any help would be awesome!

Public Sub GetSheetsInWorkspace(workspaceID As Int64)
        Dim workspace As Workspace
        workspace = smartSheet.WorkspaceResources.GetWorkspace(workspaceID, Nothing, Nothing)
        Dim folder As Folder
        folder = smartSheet.FolderResources.GetFolder(5398922303694724, Nothing)
        Dim sheets As List(Of Sheet)
        sheets = folder.Sheets
        For Each sheet In sheets
            If sheet.Name = "ALAN S. INPUT" Then
                Dim id
                id = sheet.Id
                smartSheet.SheetResources.RowResources.AttachmentResources.AttachFile(id, 1, "N:\TEST\M-TST-12346\M-TST-12346-TV.pdf", "application/pdf")
            End If
        Next
    End Sub

Solution

  • The second parameter to AttachFile is rowId, not row number. I believe your 'not found' error was due to the Row not being found To get the id of the first row, you'll need to call SheetResources.GetSheet() to get a collection of Row objects.

    BTW, backslashes should not be escaped in VB string

    Try code like this

    mySheet = ss.SheetResources.GetSheet(sheetId, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
    Dim rowId As Long
    rowId = mySheet.Rows.First.Id
    ss.SheetResources.RowResources.AttachmentResources.AttachFile(sheetId, rowId, "C:\tmp\test.pdf", "application/pdf")