Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update Properties of Uploaded Documents on Sharepoint using Web Services?

I am trying to Update/Edit Properties of Uploaded Document on Sharepoint 2007.

My code:

 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); 

Refering Link.

Getting Error: "One or more field types are not installed properly. Go to the list settings page to delete these fields".

like image 383
Preeti Avatar asked Mar 05 '10 10:03

Preeti


People also ask

How do I change document properties in SharePoint?

Click the value of the property you wish to edit under the property name, type the new value, and then press Enter on your keyboard. Your change will automatically save. To edit more than one property at a time, click Edit all, edit the properties you want to change, and then click Save.

How do I bulk edit properties in SharePoint?

Edit more than one item at a timeSelect two or more items or files in a ​​​​​​list or library. Select the information icon on the command bar to open the details pane. Enter one or more new values in the Bulk edit properties area. Save to apply the new values to all the selected items.

Do SharePoint files automatically update?

If you set a file here, the file will automatically appear in the new Document set. However the ones created before will not be updated. So if possible, I would suggest to rebuild a Document Set content type, add the files you want, and then re-add the document set to the Library you want.

How do I upload a new version of a document to SharePoint while keeping the existing version?

Right-click the document and select Add New Version, then browse to and select the document you want to add. When uploading to a document library with no versioning support: Drag the document onto the document you want to overwrite and hold for 2 seconds.


1 Answers

The following solution is provided from: http://www.codeproject.com/KB/sharepoint/File_Shunter.aspx

Note however, as mentioned in the other answer, the INTERNAL name of the field IS required.

Web.Config Keys

If you choose to, with the following added to the Web.config for your application (for this example only, alternatively you could simply include the required values [Server, Document Library, User, Domain, Password, etc.] in your code):

<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
like image 90
Joshua Avatar answered Nov 07 '22 14:11

Joshua