Get Previous versions metadata in Moss 2007 using web service RPC Method


Recently I'm facing a typical issue while get the metadata of previous versions, since I'm using Moss 2007 we don't have much options to get it. So, I'm research what are all the ways to achieve this, initially I go with Versions web service but we get only few properties so skip this approach and after several researches then I come to know that we have 2 ways to achieve this in Moss 2007.

Get Previous versions metadata in Moss 2007 using web service RPC Method :




Index:



1. Description
2. Web Service Methods
3. Source Code
4. Output
5. Conclusion

1. Description:



Recently I'm facing a typical issue while get the metadata of previous versions, since I'm using Moss 2007 we don't have much options to get it. So, I'm research what are all the ways to achieve this, initially I go with Versions web service but we get only few properties so skip this approach and after several researches then I come to know that we have 2 ways to achieve this in Moss 2007.
-> WebDav
-> RPC.
So, I'm going with RPC method, in this article I'm described detail explaination how to retrieve previous versions metadata using RPC Protocal.



Method Complexity Scalability Metadata Versions
Copy.asmx 2 4 yes no
WebDav 5 5 yes* yes**
Rpc 10 10 yes yes



2. Web Service Methods:



GetListItems: This method help us to get the list or library items from Moss 2007 using Web Service.

Syntax: GetListItems(string listName,string viewName,XmlNode query,XmlNode viewFields, string rowLimit,XmlNode queryOptions, string webID);



3. Source Code:






private static DataTable GetPreviousVersions(DataRow drCurr, Uri uri)
{
DataTable dtMetaHis = InnitiateTempFields();
string fileName = Convert.ToString(drCurr["ows_LinkFilename"]);
string fileRef = Convert.ToString(drCurr["ows_FileRef"]);

try
{

#region get metadata of previous versions using RPC method
fileRef = fileRef.Substring(fileRef.IndexOf("#") + 1);
string method = "method=list+versions%3a12.0.0.6219&service_name=%2f&document_name={0}\n";

//format the Url by passing file ref
method = String.Format(method, fileRef);

//get the bytes data of the file
List data = new List();
data.AddRange(Encoding.UTF8.GetBytes(method));


//open web client
using (WebClient wc = new WebClient())
{

// use default network credentials
wc.UseDefaultCredentials = true;
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
wc.Headers.Add("X-Vermeer-Content-Type", "application/x-www-form-urlencoded");

//pointing the admin dll
string address= "http://site:port/_vti_bin/_vti_adm/admin.dll";

// Get the Post data
string result = Encoding.UTF8.GetString(wc.UploadData(address, "POST", data.ToArray()));



// each version meta_info listed here
if (result.Contains("meta_info"))
{

//format the output as we want
string metadata = string.Format("{0}\nmeta_info", result.Substring(result.IndexOf("meta_info")));


metadata = metadata.Replace("
    ", "").Replace("
", "").Replace("", "").Replace("", "");


//looping all the versions by spliting meta_info attribute
while (metadata.Contains("meta_info="))
{
#region metadata for previous versions
DataRow drMetaVer = dtMetaHis.NewRow();
string metaInfo = string.Empty;


if (metadata.IndexOf("meta_info", 5) != -1)
{
metaInfo = metadata.Substring(0, metadata.IndexOf("meta_info", 5));
metaInfo = metaInfo.Replace("\n", "").Replace("
  • ", "\n");


    string[] metainfoDetails = metaInfo.Split('\n');


    for (int index = 1; index < metainfoDetails.Length; index++)
    {
    string fieldName = metainfoDetails[index++];
    string value = metainfoDetails[index];
    value = value.Substring(value.IndexOf("|") + 1);

    #region fill row

    if (fieldName.Contains("vti_filesize") && (value != null || value != string.Empty))
    drMetaVer["Size"] = Convert.ToInt32(value);

    if (fieldName.Contains("vti_sourcecontrolversion") && (value != null || value != string.Empty))
    {
    Int32 ver = Convert.ToInt32(value.Substring(1).Replace(".0", string.Empty));
    drMetaVer["version"] = ver.ToString();
    }


    }
    dtMetaHis.Rows.Add(drMetaVer);
    dtMetaHis.AcceptChanges();

    }
    //once metadata is completed then remove the particular version from metadata.
    metadata = metadata.Substring(metadata.IndexOf("meta_info", 5));
    #endregion
    }
    }

    }
    #endregion

    }
    catch (Exception ex)
    {
    throw;
    }
    return dtMetaHis;
    }


  • 4. Output:



    The output of this program is get the metadata of previous versions and reuse that whenever we required.

    5. Conclusion:



    This article help us to get the previous versions metadata and store the same in datatable.


    Comments

    No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: