I would like to connect DotCMIS.dll to my SharePoint but does not work correct.
I open the script in the SharePoint 2013 Management Shell.
I use my user permissions (This is not a Farm user)
Probably here's the problem with giving the correct link. org.apache.chemistry.dotcmis.binding.atompub.url=?
Have you got any idea where link in sharepoint have to go?
Website of example:
http://chemistry.apache.org/dotnet/powershell-example.html
Error
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
Important part of my Script
$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"
All Script
# 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)
Unfortunately in SharePoint Foundation 2013 I have to write own C# software.
SharePoint Foundation 2013 IMPORT\EXPORT dbo.allDocs file\files
Related
I am creating a WPF UI and I am having trouble getting the output from a foreach loop within a function into a WPF textbox. The variables I need to output ar $id $newValue and $serviceName
#Iteration through services perform string replacement
ForEach ($Response in $Responses ) {
$id = $Response.id
$newValue = $Response.value.Replace("\Service", "")
$serviceName = $Response.serviceName
Write-Output $id
Write-Output $serviceName
Write-Output $newValue
#if statement here for testing this should be removed
if ($id -eq ) {
$Payload = #{
hostName = '';
hostOperatingSystem = 0;
optionalFilter1 = '';
optionalFilter2 = '';
description = '';
serviceName = $serviceName;
sectionName = "Services";
signature = 'null';``
value = $newValue
} | ConvertTo-Json -Depth 10
#Service Configuration API PUT method call to update fullpath value
$newURI = $URI + '/' + $id
$Response = Invoke-RestMethod -Uri $newURI -Method PUT -Headers $Headers -Body $Payload -ContentType 'application/json'
}
#here for testing this should be removed
else {
$output.text = "Nothing to do"
}
}
$output.text = "Done!"
}
[xml]$Form = Get-Content "MainWindow.xaml"
$NR = (New-Object System.Xml.XmlNodeReader $Form)
$Win = [Windows.Markup.XamlReader]::Load($NR)
$URL = $win.FindName("URL")
$cid = $win.FindName("Client_ID")
$csecret = $win.FindName("Client_Secret")
$update = $Win.FindName("Update")
$output = $Win.FindName("output")
$update.Add_Click( {
$UserAuthRoute = $URL.text
$client_id = $cid.text
$client_secret = $csecret.text
if ($UserAuthRoute -eq "" -or $client_secret -eq "" -or $client_secret -eq "") {
[System.Windows.MessageBox]::Show("Please enter in all values","Variables Required")
}else{
UpdateServices $UserAuthRoute $client_id $client_secret
$output.text += "Service ID:"+$id , "Service Name: "+$serviceName, "$newValue"
}
})
$Win.ShowDialog() ```
The solution was to append the value and separate with a newline
$output.text += "Service ID: " + $id + "`r`n" + "Service Name: " + $serviceName + "`r`n" + "Service Value: " + $newValue + "`r`n"
I am trying to write in C# what this powershell script does ( See image ).
Went halfway but not much luck ( I use these namespaces
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer;
using Microsoft.SqlServer.Management.IntegrationServices;
)
I managed to get my code to work upto the point
SqlConnection ssisConnection = new SqlConnection(#"Data
Source=MHPDW2;Initial Catalog=master;Integrated Security=SSPI;");
IntegrationServices ssisServer = new IntegrationServices(ssisConnection);
foreach ?? ( you continue )
But no luck after that how to iterate through each folder. BTW the powershell script works fine with no issues.
Help! Click link below for powershell script code picture
powerscript code
$sqlConnectionString = "Data Source=MHPAPP2;Initial Catalog=master;Integrated Security=SSPI;"
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString
# Create the Integration Services object
$integrationServices = New-Object $ISNamespace".IntegrationServices" $sqlConnection
if ($integrationServices.Catalogs.Count -gt 0)
{
$catalog = $integrationServices.Catalogs["SSISDB"]
write-host "Enumerating all folders..."
$folders = $catalog.Folders
if ($folders.Count -gt 0)
{
foreach ($folder in $folders)
{
$foldername = $folder.Name
Write-Host "Exporting Folder " $foldername " ..."
# Create a new file folder
mkdir $ProjectFilePath"\"$foldername
# Export all projects
$projects = $folder.Projects
if ($projects.Count -gt 0)
{
foreach($project in $projects)
{
$fullpath = $ProjectFilePath + "\" + $foldername + "\" + $project.Name + ".ispac"
Write-Host "Exporting to " $fullpath " ..."
[System.IO.File]::WriteAllBytes($fullpath, $project.GetProjectBytes())
}
}
}
}
}
Write-Host "All done."
Can someone tell me if there is a way to get each characters location in X,Y coordinates from a PDF.
i appreciate that it may not be XY i just need a way to identify where a text character is on a page.
the characters are not raster, so i don't need to recognise them.
i have started with this.
$Path = "C:\temp\test.pdf"
$reader = New-Object iTextSharp.text.pdf.pdfreader -ArgumentList $Path
for ($page = 1; $page -le $reader.NumberOfPages; $page++)
{
$text = [iTextSharp.text.pdf.parser.PdfTextExtractor]::GetTextFromPage($reader,$page).Split([char]0x000A)
}
$reader.Close()
I'm not familiar at all with PowerShell, but you can do it like this in C#. FYI you will either need iTextSharp 5.5.10 or iText 7.0.1 for .NET to get this to run.
void Run()
{
PdfReader reader = new PdfReader("/path/to/input.pdf");
var s = PdfTextExtractor.GetTextFromPage(reader, 1, new LocationTextExtractionStrategy(new Local()));
}
private class Local : LocationTextExtractionStrategy.ITextChunkLocationStrategy
{
public LocationTextExtractionStrategy.ITextChunkLocation CreateLocation(TextRenderInfo renderInfo, LineSegment baseline)
{
// you need the info per character, so iterate all characters per TextRenderInfo
foreach (TextRenderInfo tr in renderInfo.GetCharacterRenderInfos())
{
LineSegment bl = tr.GetBaseline();
// do something with the info
Console.WriteLine(tr.GetText() + " # (" + bl.GetStartPoint()[Vector.I1] + ", " + bl.GetStartPoint()[Vector.I2] + ")");
}
return new LocationTextExtractionStrategy.TextChunkLocationDefaultImp(baseline.GetStartPoint(), baseline.GetEndPoint(), renderInfo.GetSingleSpaceWidth());
}
}
Based on blagae answer, here is a powershell script that will basically run his C# code. I didn't find an easy way to use LocationTextExtractionStrategy directly in powershell. You will need iTextSharp 5.5.10 as it is the first public version to expose LocationTextExtractionStrategy.
$Source = #"
using System;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
public class PdfHelper
{
public static void Run(string filePath)
{
PdfReader reader = new PdfReader(filePath);
for(var page = 1; page <= reader.NumberOfPages; page++)
{
PdfTextExtractor.GetTextFromPage(reader, page, new LocationTextExtractionStrategy(new Local()));
}
}
}
class Local : LocationTextExtractionStrategy.ITextChunkLocationStrategy
{
public LocationTextExtractionStrategy.ITextChunkLocation CreateLocation(TextRenderInfo renderInfo, LineSegment baseline)
{
// you need the info per character, so iterate all characters per TextRenderInfo
foreach (TextRenderInfo tr in renderInfo.GetCharacterRenderInfos())
{
LineSegment bl = tr.GetBaseline();
// do something with the info
Console.WriteLine(tr.GetText() + " # (" + bl.GetStartPoint()[Vector.I1] + ", " + bl.GetStartPoint()[Vector.I2] + ")");
}
return new LocationTextExtractionStrategy.TextChunkLocationDefaultImp(baseline.GetStartPoint(), baseline.GetEndPoint(), renderInfo.GetSingleSpaceWidth());
}
}
"#
$DLLPath = "$PSScriptRoot\iTextSharp.dll"
Add-Type -Path $DLLPath
Add-Type -ReferencedAssemblies $DLLPath -TypeDefinition $Source -Language CSharp
$Path = "C:\temp\test.pdf"
[PdfHelper]::Run($Path)
I am trying to use ASP.NET to return the total startup RAM on a VM on a Hyper-V server. The function I have is this:
public static double GetRamVM(string vm, string host)
{
string cmdToRun = "get-vmmemory -name " + vm + " -computername " + host + " | select Startup" ;
var shell = PowerShell.Create();
shell.Commands.AddScript(cmdToRun);
var mem = shell.Invoke();
foreach (PSObject obj in mem)
{
var startMem = obj.Members["Startup"].Value;
return (double)startMem;
}
return 9999.9999;
}
However, whenever I return it - it ALWAYS returns as 9999.9999. I know that the command works, as when I run it manually in a powershell window I get the result that I want.
Please help - as I am going out of my mind.
Edit:
The manual run of the script looks like this
PS C:\Users\mark> Get-VMMemory -vmname "test test" -computername "testhost" | select Startup
Startup
-------
536870912
You could try using the -ExpandProperty on the PowerShell Select cmdlet. This will return a number for the account of memory being used and not an PS-object, so you wont have to extract the value in your C code.
public static double GetRamVM(string vm, string host)
{
string cmdToRun = "get-vmmemory -name " + vm + " -computername " + host + " | select -ExpandProperty Startup" ;
var shell = PowerShell.Create();
shell.Commands.AddScript(cmdToRun);
var mem = shell.Invoke();
return (double)mem;
}
I found this PowerShell Script that searches for Exchange Servers in the Domain.
Function Get-ExchangeServerInSite {
$ADSite = [System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]
$siteDN = $ADSite::GetComputerSite().GetDirectoryEntry().distinguishedName
$configNC=([ADSI]"LDAP://RootDse").configurationNamingContext
$search = new-object DirectoryServices.DirectorySearcher([ADSI]"LDAP://$configNC")
$objectClass = "objectClass=msExchExchangeServer"
$site = "msExchServerSite=$siteDN"
$search.Filter = "(&($objectClass)($site))"
$search.PageSize=1000
[void] $search.PropertiesToLoad.Add("name")
[void] $search.PropertiesToLoad.Add("msexchcurrentserverroles")
[void] $search.PropertiesToLoad.Add("networkaddress")
$search.FindAll() | %{
New-Object PSObject -Property #{
Name = $_.Properties.name[0]
FQDN = $_.Properties.networkaddress |
%{if ($_ -match "ncacn_ip_tcp") {$_.split(":")[1]}}
Roles = $_.Properties.msexchcurrentserverroles[0]
}
}
}
$role = #{
2 = "MB"
4 = "CAS"
16 = "UM"
32 = "HT"
64 = "ET"
}
foreach ($server in Get-ExchangeServerinSite) {
$roles = ($role.keys | ?{$_ -band $server.roles} | %{$role.Get_Item($_)}) -join ", "
$server | select Name, #{n="Roles";e={$roles}},FQDN
}
Because I need the same task in C# code without using PowerShell. I tried using the .Net classes the same way and even debuged both scripts and the info is the same.
Now my problem. The PowerShell script correctly displays the server and the C# code returns an empty collection.
Here is the C#
string siteDN = ActiveDirectorySite.GetComputerSite().GetDirectoryEntry().Properties["distinguishedName"].Value.ToString();
DirectoryEntry RootDSE = new DirectoryEntry( #"LDAP://RootDSE" );
string baseStr = #"LDAP://" + RootDSE.Properties["configurationNamingContext"].Value ;
DirectorySearcher searcher = new DirectorySearcher(baseStr );
string classObj = "objectClass=msExchExchangeServer";
string site = "msExchServerSite="+siteDN;
searcher.Filter = string.Format("(&({0})({1}))",classObj,site);
searcher.PropertiesToLoad.Add( "name" );
searcher.PageSize = 1000;
searcher.ServerTimeLimit = new TimeSpan(0,1,0);
searcher.CacheResults = false;
SearchResultCollection coll = searcher.FindAll();
The only difference I could find was the [ADSI] tag in the PowerShell code but I couldn't find out what the C# part is from that.