使用SharePoint Web Serivce(3)--Add a new Item with HyperLink and User Type Column
2009-04-27 14:45
711 查看
前面的两篇,讲了如何创建 修改一个list item.但是在这些item中,我们都只是使用了简单的Text类型的Field,如果我们使用一些相对复杂的Field,改怎么做,例如HyperLink 和User Type的column.
先讲HyperLink type的Field.如果先前有使用过Object Model去读取一个Hyperlink Type的Field,就会发现,如果用ToString(),就会得到一个"url,description"格式的字符串.所以,这也是我们在XML要用到的格式.
string strBatch = @"<Method ID='1' Cmd='New'>
<Field Name='Title'>Sample Title</Field>
<Field Name='Url'>http://www.microsoft.com, Microsoft Site</Field>
</Method>";
使用User Type的Field就稍微麻烦一点.如果你看过Object Model读取的User Field的值,就会发现是一串值就像"ID;#domain\\account....",但是在web service中,没有那么麻烦 只要"ID;domian\\account",所以,我们要先得到ID值,因此我们要用到另外一个Web Service Usergroup.asmx
UserGroupWebService.UserGroup ugService=new UserGroupWebService.UserGroup();
XmlNode ugNode=ugService.GetUserInfo("Server\\LoginName");
XmlDocument ugdoc = new XmlDocument();
ugdoc.LoadXml(ugNode.OuterXml);
XmlNodeList ugList = ugdoc.GetElementsByTagName("User");
string id = ugList[0].Attributes["ID"].Value;
然后如以下格式:
<Field Name='User'>ID;#domian\\account</Field>
先讲HyperLink type的Field.如果先前有使用过Object Model去读取一个Hyperlink Type的Field,就会发现,如果用ToString(),就会得到一个"url,description"格式的字符串.所以,这也是我们在XML要用到的格式.
string strBatch = @"<Method ID='1' Cmd='New'>
<Field Name='Title'>Sample Title</Field>
<Field Name='Url'>http://www.microsoft.com, Microsoft Site</Field>
</Method>";
使用User Type的Field就稍微麻烦一点.如果你看过Object Model读取的User Field的值,就会发现是一串值就像"ID;#domain\\account....",但是在web service中,没有那么麻烦 只要"ID;domian\\account",所以,我们要先得到ID值,因此我们要用到另外一个Web Service Usergroup.asmx
UserGroupWebService.UserGroup ugService=new UserGroupWebService.UserGroup();
XmlNode ugNode=ugService.GetUserInfo("Server\\LoginName");
XmlDocument ugdoc = new XmlDocument();
ugdoc.LoadXml(ugNode.OuterXml);
XmlNodeList ugList = ugdoc.GetElementsByTagName("User");
string id = ugList[0].Attributes["ID"].Value;
然后如以下格式:
<Field Name='User'>ID;#domian\\account</Field>
相关文章推荐
- 使用SharePoint Web Serivce(4)-HyperLink Type Column 中令我发狂的空格
- 使用SharePoint Web Serivce(1)--Add a NEW item to a list.
- 使用SharePoint Web Serivce(5)--得到新添加Item的ID,返回的XML的使用
- 使用SharePoint Web Serivce(2)--Update Delete a item in a list
- Creating and Using a New Content Type in SharePoint 2007(zhuan:http://www.sharepointproconnections.com/article/sharepoint-portal
- hyperlink column and a user column
- Upload a file to Sharepoint 2007 using webservices with a specific content type
- Office and SharePoint 2007 User's Guide: Integrating SharePoint with Excel, Outlook, Access and Word
- Working with user roles and permissions in SharePoint Object Model
- Developing SharePoint WebParts using User Controls and Web Applications
- [转]Working with user roles and permissions in SharePoint Object Model
- Developing SharePoint WebParts using User Controls and Web Applications
- Customize the SharePoint 2013 search experience with a Content Enrichment web service
- 使用Sharepoint web应用程序用户满意度调查程序详解
- 记录一个:Create, Update, Delete and Copy Item Activity in SharePoint 2010 Workflow
- Create custom Task List and Forms in SharePoint 2010 with Visual Studio 2012
- Checking if a user is a member in a SharePoint group within web InfoPath 2010 forms
- 使用Host-Provider方式开发的App,无法获取SharePoint Online中的item
- FW:Data View Web Parts and Ghosting in SharePoint Version 2
- Custom redirect after creating a new Sharepoint Item