如何通过CSOM SaveBinaryDirect上传文档路径

时间:2018-10-25 03:18:20

标签: vb.net sharepoint csom

我能够使用CSOM在sharepoint(Office 365)上上传文档。参见下面的代码:

        Dim filePath As String = "C:\temp\Testfile.txt"
        Dim LibraryName = "Documents"
        Dim siteURL = "https://myCompany.sharepoint.com/MySite/"
        Dim fileName = "Testfile"
        Dim serverURL As String
        Dim passWord As New System.Security.SecureString

        For Each fern As String In "Password123"
            passWord.AppendChar(fern)
        Next
        Using ct As New ClientContext(siteURL)


            ct.Credentials = New SharePointOnlineCredentials("username@myCompany.onmicrosoft.com",
                                                             passWord)

            Dim web = ct.Web
            Dim myLibrary = web.Lists.GetByTitle(LibraryName)
            Dim folder = myLibrary.RootFolder

            ct.Load(folder, Function(f) f.ServerRelativeUrl)

            ct.ExecuteQuery()
            serverURL = folder.ServerRelativeUrl

        End Using

        Dim fs As New FileStream(filePath, FileMode.Open, FileAccess.Read)
        Dim ct2 As New ClientContext(siteURL)
        ct2.Credentials = New SharePointOnlineCredentials("username@myCompany.onmicrosoft.com",
                                                             passWord)
        Microsoft.SharePoint.Client.File.SaveBinaryDirect(ct2, serverURL + "/" + System.IO.Path.GetFileName(filePath), fs, True)

        ct2.Load(file)
        ct2.ExecuteQuery()

但是,我还需要将文件路径存储在数据库中。目的可能类似于将来提供下载URL或只是显示它。

现在,Sharepoint网站的URL是: https://mycompany.sharepoint.com/siteName/Documents/MyFile.txt

,但是如果我们从网站手动复制URL,则为: https://mycompany.sharepoint.com/:w:/g/siteName/Esdesdsweeebjhmbgdbgvxchm63fn6jkoss5t8u4r3ew2j7e?e=trWePO

我们应该将简单的人类可读路径存储在DB中吗?如果可以,我们是否可以使用此URL提供下载/查看功能? 如果我们选择存储第二种格式,那么如何导出呢?有参考资料吗?

谢谢

0 个答案:

没有答案