【问题标题】:How does one successfully call createDocument through the Sharepoint CMIS connector webservice?如何通过 Sharepoint CMIS 连接器 Web 服务成功调用 createDocument?
【发布时间】:2012-01-27 16:28:33
【问题描述】:

我收到以下错误:

服务方法的一个或多个输入参数丢失或无效。

ObjectService.createDocument(repositoryId, objectPropertyCollection, rootFolderId, myContentStream, ObjectService.enumVersioningState.none, null, addAclcontrol, null, ref extType);

被调用。这就是我设置所有这些参数的方式:

//Get repositoryId, and rootFolder id.
string repositoryId = RepositoryStore[contentType];  
RepositoryService.cmisRepositoryInfoType repoInfo =_controller.RepositoryClient.getRepositoryInfo(repositoryId, new RepositoryService.cmisExtensionType());  
string rootFolder = repoInfo.rootFolderId;  
string theActualName = filename.Substring(filename.LastIndexOf("\\") + 1);  

//Create a cmisContentStreamType.  
ObjectService.cmisContentStreamType fileStream = new ObjectService.cmisContentStreamType();  
fileStream.stream = File.ReadAllBytes(filename);
fileStream.filename = theActualName;
fileStream.length = fileStream.stream.Length.ToString();
fileStream.mimeType = "application/pdf";

//Setting the acl objects needed to create the document. 
ObjectService.cmisAccessControlEntryType homeMembers = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType owners = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType viewers = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType visitors = new ObjectService.cmisAccessControlEntryType();

ObjectService.cmisAccessControlPrincipalType ownersPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
ownersPrincipalType.principalId = @"Home Owners";
owners.principal = ownersPrincipalType;
owners.permission = new string[] { "cmis:all" };
ObjectService.cmisAccessControlPrincipalType homePrincipalType = new ObjectService.cmisAccessControlPrincipalType();
homePrincipalType.principalId = @"Home Members";
homeMembers.principal = homePrincipalType;
homeMembers.permission = new string[] { "cmis:write" };
ObjectService.cmisAccessControlPrincipalType viewersPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
homePrincipalType.principalId = @"Viewers";
homeMembers.principal = viewersPrincipalType;
homeMembers.permission = new string[] { "cmis:read" };
ObjectService.cmisAccessControlPrincipalType visitorsPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
homePrincipalType.principalId = @"Home Visitors";
homeMembers.principal = visitorsPrincipalType;
homeMembers.permission = new string[] { "cmis:read" };

ObjectService.cmisAccessControlEntryType[] addAclControl = new ObjectService.cmisAccessControlEntryType[] { homeMembers, owners, viewers, visitors };

ObjectService.cmisExtensionType exttype = new ObjectService.cmisExtensionType();

ObjectService.cmisPropertiesType objectPropertyArray = MakedocumentPropertiesList(theActualName,fileStream.length);


private ObjectService.cmisPropertiesType MakedocumentPropertiesList(string fileName,string contentStreamLength)
{
List<ObjectService.cmisProperty> arrProps = new List<ObjectService.cmisProperty>();
ObjectService.cmisPropertiesType props = new ObjectService.cmisPropertiesType();

arrProps.Add(GetPropertyString("Name", "cmis:name", "mydocuemntname", "FileLeafRef"));
arrProps.Add(GetPropertyId("cmis:baseTypeId", "cmis:baseTypeId", "cmis:document",   "cmis:baseTypeId"));

props.Items = arrProps.ToArray();

return props;

}

private ObjectService.cmisPropertyString GetPropertyString(string displayName, string    queryName, string value, string localName)
{
ObjectService.cmisPropertyString title = new ObjectService.cmisPropertyString();
title.localName = localName;
title.displayName = displayName;
title.queryName = queryName;
title.propertyDefinitionId = displayName;
title.value = new string[] { value };
return title;
}

private ObjectService.cmisPropertyId GetPropertyId(string displayName, string queryName, string value, string localName)
{
ObjectService.cmisPropertyId id = new  ObjectService.cmisPropertyId();
id.localName = localName;
id.displayName = displayName;
id.queryName = queryName;
id.propertyDefinitionId = displayName;
id.value = new string[] { value };
return id;
}

【问题讨论】:

    标签: c# sharepoint-2010 cmis


    【解决方案1】:

    您不能设置“cmis:baseTypeId”属性,但必须设置“cmis:objectTypeId”属性。尝试交换您的第二个属性的 ID。

    除此之外,您应该看看DotCMIS。它可以为您节省大量工作。

    【讨论】:

    • 谢谢。这让我朝着正确的方向前进。最后只是将 cmisPropertyType 更改为有两个条目,一个是包含 ObjectTypeId 信息的 cmisPropertyId,另一个是包含文件名的 cmisPropertyString。
    【解决方案2】:

    我拿走了你的代码,我更正了它..现在它对我有用..看看:

            string user = txtLogin.Text;
            string password = txtPwd.Text;
            DemoCMISForms.RepositoryService.RepositoryServicePortClient repService = new DemoCMISForms.RepositoryService.RepositoryServicePortClient("BasicHttpBinding_IRepositoryServicePort2");
            repService.ClientCredentials.UserName.UserName = user;
            repService.ClientCredentials.UserName.Password = password;
    
            DemoCMISForms.ObjectService.ObjectServicePortClient objectService = new DemoCMISForms.ObjectService.ObjectServicePortClient("BasicHttpBinding_IObjectServicePort2");
    
            objectService.ClientCredentials.UserName.UserName = user;
            objectService.ClientCredentials.UserName.Password = password;
    
            //Get repositoryId, and rootFolder id.
    
            RepositoryService.cmisRepositoryInfoType repoInfo = repService.getRepositoryInfo(idRep, new RepositoryService.cmisExtensionType());
            string rootFolder = repoInfo.rootFolderId;
            string theActualName = textBox1.Text.Substring(textBox1.Text.LastIndexOf("\\") + 1);
    
            //Create a cmisContentStreamType.  
            ObjectService.cmisContentStreamType fileStream = new ObjectService.cmisContentStreamType();
            fileStream.stream = File.ReadAllBytes(textBox1.Text);
            fileStream.filename = theActualName;
            fileStream.length = fileStream.stream.Length.ToString();
            fileStream.mimeType = "text/plain";
    
            //Setting the acl objects needed to create the document. 
            ObjectService.cmisAccessControlEntryType homeMembers = new ObjectService.cmisAccessControlEntryType();
            ObjectService.cmisAccessControlEntryType owners = new ObjectService.cmisAccessControlEntryType();
            ObjectService.cmisAccessControlEntryType viewers = new ObjectService.cmisAccessControlEntryType();
            ObjectService.cmisAccessControlEntryType visitors = new ObjectService.cmisAccessControlEntryType();
    
            ObjectService.cmisAccessControlPrincipalType ownersPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
            ownersPrincipalType.principalId = @"Home Owners";
            owners.principal = ownersPrincipalType;
            owners.permission = new string[] { "cmis:all" };
            ObjectService.cmisAccessControlPrincipalType homePrincipalType = new ObjectService.cmisAccessControlPrincipalType();
            homePrincipalType.principalId = @"Home Members";
            homeMembers.principal = homePrincipalType;
            homeMembers.permission = new string[] { "cmis:write" };
            ObjectService.cmisAccessControlPrincipalType viewersPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
            viewersPrincipalType.principalId = @"Viewers";
            viewers.principal = viewersPrincipalType;
            viewers.permission = new string[] { "cmis:read" };
            ObjectService.cmisAccessControlPrincipalType visitorsPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
            visitorsPrincipalType.principalId = @"Home Visitors";
            visitors.principal = visitorsPrincipalType;
            visitors.permission = new string[] { "cmis:read" };
    
            ObjectService.cmisAccessControlEntryType[] addAclControl = new ObjectService.cmisAccessControlEntryType[] { homeMembers, owners, viewers, visitors };
    
            ObjectService.cmisExtensionType exttype = new ObjectService.cmisExtensionType();
    
            ObjectService.cmisPropertiesType objectPropertyArray = MakedocumentPropertiesList(theActualName, fileStream.length);
    
            objectService.createDocument(idRep, objectPropertyArray, idFolder, fileStream, ObjectService.enumVersioningState.major, null, addAclControl, null, ref exttype);
        }
    
        private ObjectService.cmisPropertiesType MakedocumentPropertiesList(string fileName, string contentStreamLength)
        {
            List<ObjectService.cmisProperty> arrProps = new List<ObjectService.cmisProperty>();
            ObjectService.cmisPropertiesType props = new ObjectService.cmisPropertiesType();
    
            arrProps.Add(GetPropertyString(fileName, "cmis:name", fileName, "FileLeafRef"));
            arrProps.Add(GetPropertyId("cmis:objectTypeId", "cmis:objectTypeId", "cmis:document", "cmis:objectTypeId"));
    
            props.Items = arrProps.ToArray();
    
            return props;
    
        }
    
        private ObjectService.cmisPropertyString GetPropertyString(string displayName, string queryName, string value, string localName)
        {
            ObjectService.cmisPropertyString title = new ObjectService.cmisPropertyString();
            title.localName = localName;
            title.displayName = displayName;
            title.queryName = queryName;
            title.propertyDefinitionId = displayName;
            title.value = new string[] { value };
            return title;
        }
    
        private ObjectService.cmisPropertyId GetPropertyId(string displayName, string queryName, string value, string localName)
        {
            ObjectService.cmisPropertyId id = new ObjectService.cmisPropertyId();
            id.localName = localName;
            id.displayName = displayName;
            id.queryName = queryName;
            id.propertyDefinitionId = displayName;
            id.value = new string[] { value };
            return id;
        }
    

    我发现一些变量在复制粘贴操作后保持不变!我还将此示例与文本文件一起使用! 希望能帮到你!

    PS:我还没有处理文档类型的问题,我只是用文本文件制作了示例函数。另外,我从 SP 站点调用的列表中的版本控制也是一个问题,所以我必须先验证一下添加任何文件..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多