Smartsheet API 附件
Smartsheet API Attachement
智能表中的附件有问题 API。
一直提示此行不支持文件路径格式
smartSheet.SheetResources.RowResources.AttachmentResources.AttachFile(id, 1, "N:\TEST\M-TST-12346\M-TST-12346-TV.pdf", "application/pdf")
任何帮助都会很棒!
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
也许将您正在做的事情与作为 SDK 的一部分提供的 integration test code 进行比较会有所帮助?具体来说,我链接到的文件中的 AttachFileAndUrlToRow 方法包含用于向行添加附件的这一行:
Attachment attachment = smartsheet.SheetResources.RowResources.AttachmentResources.AttachFile(sheetId, rowId, path, null);
...其中path的值定义如下:
string path = "../../../IntegrationTestSDK/TestFile.txt";
将该测试代码与您发布的代码进行比较,我发现了一些差异:
- 您的代码在文件路径中使用(单个)反斜杠 (\),而 SDK 测试代码使用 forward-slashes (/)
- 您指定的路径使用驱动器映射 (N:\),而 SDK 测试代码指定的是相对路径
- 您为最后一个参数 (
application/pdf
) 传递了一个值,而 SDK 测试代码为最后一个参数指定了 null
。
也许作为故障排除的第一步,转义 文件路径中的每个反斜杠——即,为每个反斜杠添加一个额外的反斜杠:
smartSheet.SheetResources.RowResources.AttachmentResources.AttachFile(id, 1, "N:\TEST\M-TST-12346\M-TST-12346-TV.pdf", "application/pdf")
如果这不能解决您的问题,那么或许可以尝试将每个反斜杠更改为 forward-slash(与 SDK 测试代码所做的一致):
smartSheet.SheetResources.RowResources.AttachmentResources.AttachFile(id, 1, "N:/TEST/M-TST-12346/M-TST-12346-TV.pdf", "application/pdf")
此外(尽管可能与您的问题无关)- 看起来您正在为 rowId 传递值 1
,这是不正确的- rowId 应该是一个 GUID(例如,更像这样的东西:4583173393803140
)。
AttachFile 的第二个参数是rowId,不是行号。我相信您的 'not found' 错误是由于未找到该行造成的
要获取第一行的 ID,您需要调用 SheetResources.GetSheet() 来获取 Row 对象的集合。
顺便说一句,反斜杠应该不在VB字符串
中被转义
试试这样的代码
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")
智能表中的附件有问题 API。
一直提示此行不支持文件路径格式
smartSheet.SheetResources.RowResources.AttachmentResources.AttachFile(id, 1, "N:\TEST\M-TST-12346\M-TST-12346-TV.pdf", "application/pdf")
任何帮助都会很棒!
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
也许将您正在做的事情与作为 SDK 的一部分提供的 integration test code 进行比较会有所帮助?具体来说,我链接到的文件中的 AttachFileAndUrlToRow 方法包含用于向行添加附件的这一行:
Attachment attachment = smartsheet.SheetResources.RowResources.AttachmentResources.AttachFile(sheetId, rowId, path, null);
...其中path的值定义如下:
string path = "../../../IntegrationTestSDK/TestFile.txt";
将该测试代码与您发布的代码进行比较,我发现了一些差异:
- 您的代码在文件路径中使用(单个)反斜杠 (\),而 SDK 测试代码使用 forward-slashes (/)
- 您指定的路径使用驱动器映射 (N:\),而 SDK 测试代码指定的是相对路径
- 您为最后一个参数 (
application/pdf
) 传递了一个值,而 SDK 测试代码为最后一个参数指定了null
。
也许作为故障排除的第一步,转义 文件路径中的每个反斜杠——即,为每个反斜杠添加一个额外的反斜杠:
smartSheet.SheetResources.RowResources.AttachmentResources.AttachFile(id, 1, "N:\TEST\M-TST-12346\M-TST-12346-TV.pdf", "application/pdf")
如果这不能解决您的问题,那么或许可以尝试将每个反斜杠更改为 forward-slash(与 SDK 测试代码所做的一致):
smartSheet.SheetResources.RowResources.AttachmentResources.AttachFile(id, 1, "N:/TEST/M-TST-12346/M-TST-12346-TV.pdf", "application/pdf")
此外(尽管可能与您的问题无关)- 看起来您正在为 rowId 传递值 1
,这是不正确的- rowId 应该是一个 GUID(例如,更像这样的东西:4583173393803140
)。
AttachFile 的第二个参数是rowId,不是行号。我相信您的 'not found' 错误是由于未找到该行造成的 要获取第一行的 ID,您需要调用 SheetResources.GetSheet() 来获取 Row 对象的集合。
顺便说一句,反斜杠应该不在VB字符串
中被转义试试这样的代码
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")