DotCMIS连接到SharePoint Foundation 2013

时间:2014-12-10 12:53:22

标签: c# sharepoint sharepoint-2010

我想将DotCMIS.dll连接到我的SharePoint,但无效。

我在SharePoint 2013 Management Shell中打开脚本。

我使用我的用户权限(这不是Farm用户)

可能是提供正确链接的问题。 org.apache.chemistry.dotcmis.binding.atompub.url =?

您是否知道sharepoint中的链接必须去哪里?

示例网站:

http://chemistry.apache.org/dotnet/powershell-example.html

错误

You cannot call a method on a null-valued expression.
At line:6 char:7
+       $b = $contentStream.Stream.Read($buffer, 0, 4096)
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

我的剧本的重要部分

$sp["org.apache.chemistry.dotcmis.binding.atompub.url"] = "http://localhost/_layouts/15/start.aspx#/SitePages/WebSite.aspx"
    $sp["org.apache.chemistry.dotcmis.user"] = "mylogin"
    $sp["org.apache.chemistry.dotcmis.password"] = "mypassword"

所有剧本

# load DotCMIS DLL
[Reflection.Assembly]::LoadFile("C:\dotCmisServer\DotCMIS.dll")


# -----------------------------------------------------------------

# helper functions
function New-GenericDictionary([type] $keyType, [type] $valueType) {  
   $base = [System.Collections.Generic.Dictionary``2]  
   $ct = $base.MakeGenericType(($keyType, $valueType))  
   New-Object $ct
}

function New-ContentStream([string] $file, [string] $mimetype) {
   $fileinfo = ([System.IO.FileInfo]$file)

   $contentStream = New-Object "DotCMIS.Data.Impl.ContentStream"
   $contentStream.Filename = $fileinfo.Name
   $contentStream.Length = $fileinfo.Length
   $contentStream.MimeType = $mimetype
   $contentStream.Stream = $fileinfo.OpenRead()

   $contentStream
}

function Download-ContentStream([DotCMIS.Client.IDocument] $document, [string] $file) {
   $contentStream = $document.GetContentStream()   
   $fileStream = [System.IO.File]::OpenWrite($file)

   $buffer = New-Object byte[] 4096  
   do {  
      $b = $contentStream.Stream.Read($buffer, 0, 4096)  
      $fileStream.Write($buffer, 0, $b)  
   }  
   while ($b -ne 0)

   $fileStream.Close()
   $contentStream.Stream.Close()
}


# -----------------------------------------------------------------

# create session
$sp = New-GenericDictionary string string
$sp["org.apache.chemistry.dotcmis.binding.spi.type"] = "atompub"
$sp["org.apache.chemistry.dotcmis.binding.atompub.url"] = "http://localhost/_layouts/15/start.aspx#/SitePages/WebSite.aspx"
$sp["org.apache.chemistry.dotcmis.user"] = "mylogin"
$sp["org.apache.chemistry.dotcmis.password"] = "mypassword"

$factory = [DotCMIS.Client.Impl.SessionFactory]::NewInstance()
$session = $factory.GetRepositories($sp)[0].CreateSession()


# print the repository infos
$session.RepositoryInfo.Id
$session.RepositoryInfo.Name
$session.RepositoryInfo.Vendor
$session.RepositoryInfo.ProductName
$session.RepositoryInfo.ProductVersion


# get root folder
$root = $session.GetRootFolder()


# print root folder children
$children = $root.GetChildren()
foreach ($object in $children) {
   $object.Name + "     (" + $object.ObjectType.Id + ")" 
}


# run a quick query
$queryresult = $session.Query("SELECT * FROM cmis:document", $false)
foreach ($object in $queryresult) {
   foreach ($item in $object.Properties) {
      $item.QueryName + ": " + $item.FirstValue
   }
   "----------------------------------"
}


# create a folder
$folderProperties = New-GenericDictionary string object
$folderProperties["cmis:name"] = "myNewFolder"
$folderProperties["cmis:objectTypeId"] = "cmis:folder"

$folder = $root.CreateFolder($folderProperties)


# create a document 
$documentProperties = New-GenericDictionary string object
$documentProperties["cmis:name"] = "myNewDocument"
$documentProperties["cmis:objectTypeId"] = "cmis:document"

$source = $home + "\source.txt"
$mimetype = "text/plain"
$contentStream = New-ContentStream $source $mimetype

$doc = $folder.CreateDocument($documentProperties, $contentStream, $null)


# download a document
$target = $home + "\target.txt"
Download-ContentStream $doc $target


# clean up
$doc.Delete($true)
$folder.Delete($true)

1 个答案:

答案 0 :(得分:0)

不幸的是,在SharePoint Foundation 2013中,我必须编写自己的C#软件。

SharePoint Foundation 2013 IMPORT\EXPORT dbo.allDocs file\files