2010-03-05 5 views
8

tôi đang cố gắng để cập nhật/chỉnh sửa thuộc tính của Uploaded tài liệu trên Sharepoint 2007.Làm thế nào để cập nhật các thuộc tính của tài liệu được tải lên trên Sharepoint bằng dịch vụ Web?

Mã của tôi:

Lists listService = new Lists(); 
listService.PreAuthenticate = true; 
listService.Credentials = new NetworkCredential(username,password); 
listService.Url = "http://myserver/SiteName/_vti_bin/lists.asmx"; 

string strBatch = 

        "<Method ID='1' Cmd='Update'> " 
        + " <Field Name='ID'>3</Field> " 
        + " <Field Name='Name'>Preeti</Field> "     
        + " </Method> "; 

XmlDocument xmlDoc = new System.Xml.XmlDocument(); 
System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch"); 
elBatch.SetAttribute("OnError", "Continue"); 

elBatch.SetAttributeNode("UserName", "Preeti"); 
elBatch.InnerXml = strBatch; 
XmlNode ndReturn = listService.UpdateListItems(ListName, elBatch); 

MessageBox.Show(ndReturn.OuterXml); 

đề cậpLink.

Lỗi: "Một hoặc nhiều loại trường không được cài đặt đúng cách. Đi tới trang cài đặt danh sách để xóa các trường này".

Trả lời

1

Các giải pháp sau đây được cung cấp từ: tuy nhiên http://www.codeproject.com/KB/sharepoint/File_Shunter.aspx

Lưu ý, như đã đề cập trong câu trả lời khác, tên NỘI của lĩnh vực này là bắt buộc.

Web.Config Phím

Nếu bạn chọn, với những sản phẩm sau được bổ sung vào Web.config cho các ứng dụng của bạn (ví dụ này chỉ, cách khác bạn chỉ có thể bao gồm các giá trị cần thiết [Server, Thư Viện Tài Liệu , dùng, tên miền, mật khẩu, vv] trong mã của bạn):

<configuration> 
<appSettings> 

<add key="SharePointServer" value=http://SP Portal/Site/> 
<add key="DocLibrary" value="Doclib"/> 
<add key="User" value="User"/> 
<add key="Domain" value="Domain"/> 
<add key="Pwd" value="Pwd"/> 
<add key="GlobalSharedPath" value="D:\"/> 
</appSettings> 

Code:

Public Function WSSUpdateFile(ByVal sFileName As String, ByVal sSiteDoc As String, ByVal sTestCol As String) As String 

     Dim sUser As String = ConfigurationManager.AppSettings("User") 
     Dim sPwd As String = ConfigurationManager.AppSettings("Pwd") 
     Dim sDomain As String = ConfigurationManager.AppSettings("Domain") 
     Dim sFileIDinList As String 
     Dim strBatch As String = "" 
     sSiteDoc = Replace(sSiteDoc, "%20", " ") 
     sSiteDoc = Replace(sSiteDoc, "\", "/") 
     Dim sFinalFilePath As String 
     Dim sSPURL As String = ConfigurationManager.AppSettings("SharePointServer") 
     Dim sDocLib As String = ConfigurationManager.AppSettings("DocLibrary") 
     Try 
      Dim netAccess As System.Net.NetworkCredential = New System.Net.NetworkCredential(sUser, sPwd, sDomain) 
      Dim listService As New SPLists.Lists 
      listService.Url = sSPURL & "/_vti_bin/lists.asmx" 
      listService.Credentials = netAccess 
      sFileIDinList = sGetID(listService.Url, sDocLib, sFileName) 
      If sFileIDinList <> "" Then 
       sFinalFilePath = sSPURL & "/" & sDocLib & "/" & sFileName 
       'Now we have FileID so update the list 
       strBatch = "<Method ID='1' Cmd='Update'>" + _ 
        "<Field Name = 'ID'>" & sFileIDinList & "</Field>" + _ 
        "<Field Name = 'FileRef'>" & sFinalFilePath & "</Field>" + _ 
        "<Field Name = 'TestCol'>" & sTestCol & "</Field>" + _ 
        "</Method>" 
       Dim xmlDoc = New System.Xml.XmlDocument 
       Dim elBatch As System.Xml.XmlElement = xmlDoc.createelement("Batch") 
       elBatch.InnerXml = strBatch 
       Dim ndreturn As System.Xml.XmlNode = listService.UpdateListItems(sDocLib, elBatch) 
      End If 
      Return "TRUE" 
     Catch ex As Exception 
      Return ex.Message 
     End Try 
    End Function 

Private Function sGetID(ByVal sURL As String, ByVal sListGUID As String, ByVal sFileName As String) As String 
     Dim sUser As String = ConfigurationManager.AppSettings("User") 
     Dim sPwd As String = ConfigurationManager.AppSettings("Pwd") 
     Dim sDomain As String = ConfigurationManager.AppSettings("Domain") 
     Dim netAccess As System.Net.NetworkCredential = New System.Net.NetworkCredential(sUser, sPwd, sDomain) 
     Dim L As New SPLists.Lists 
     L.Credentials = netAccess 
     L.Url = sURL 
     Dim xmldoc As XmlDocument = New XmlDocument 
     Dim query As XmlNode = xmldoc.CreateNode(XmlNodeType.Element, "Query", "") 
     query.InnerXml = "<OrderBy><FieldRef Name='Modified' Ascending='False'></FieldRef></OrderBy>""" 
     Try 
      Dim caml As XmlNode = L.GetListItems(sListGUID, Nothing, query, Nothing, "1", Nothing) 
      Dim id As String = caml.ChildNodes(1).ChildNodes(1).Attributes("ows_ID").Value 
      Return id 
     Catch ex As Exception 
      Return ex.Message 
     End Try 
    End Function 
0

Kiểm tra để đảm bảo bạn đang sử dụng tên nội bộ của trường.

To get the internal name of the field, open the "New" form and click "View Source" from context menu (right click any where in the "New" form page to open the context menu). You will see the fields along with their internal names near the end of the source file.

nhìn vào mã:

string strBatch = 

       "<Method ID='1' Cmd='Update'> " 
       + " <Field Name='ID'>3</Field> " 
       + " <Field Name='Name'>Preeti</Field> "     
       + " </Method> "; 

...

elBatch.SetAttributeNode("UserName", "Preeti"); 

là những thực sự hai thuộc tính riêng biệt trong SharePoint?

0

Hãy thử sử dụng công cụ U2UCamlCreator để kiểm tra các truy vấn của bạn.
Công cụ này sẽ giúp bạn tạo các lô để cập nhật các trường chia sẻ và nhiều tính năng khác.