Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How to obtain the ID of a newly uploaded document using web services (c#, .net)? Is the following the best way to obtain Doc ID?

private string sGetID(string sURL, string sListGUID, string sFileName)
{
    string sUser = ConfigurationManager.AppSettings("User");
    string sPwd = ConfigurationManager.AppSettings("Pwd");
    string sDomain = ConfigurationManager.AppSettings("Domain");
    System.Net.NetworkCredential netAccess = new System.Net.NetworkCredential(sUser, sPwd, sDomain);
    SPLists.Lists L = new SPLists.Lists();
    L.Credentials = netAccess;
    L.Url = sURL;
    XmlDocument xmldoc = new XmlDocument();
    XmlNode query = xmldoc.CreateNode(XmlNodeType.Element, "Query", "");
    query.InnerXml = "<OrderBy><FieldRef Name='Modified' " + "Ascending='False'></FieldRef></OrderBy>\"";
    try {
        XmlNode caml = L.GetListItems(sListGUID, null, query, null, "1", null);
        string id = caml.ChildNodes(1).ChildNodes(1).Attributes("ows_ID").Value;
        return id;
    } catch (Exception ex) {
        return ex.Message;
    }
}
share|improve this question
1  
I think that you should use "Created" field instead of "Modified", in your solution you will get items ordered by update time. –  Alexander Oct 24 '11 at 19:51

2 Answers 2

_dlc_DocId is the internal field that has allows you to change or retrive the document id. also agree with row limit. but if a newly created/uploaded document as in version 1. then maybe insted of modified you can use created

kind regards

share|improve this answer

I'd add a RowLimit node to the CAML Query, just to be sure to limit the result set to 1, ensures that your web services request brings back only the data it needs (imagine if you had thousands of items in that library!).

share|improve this answer
    
How to use SiteData.GetURLSegments method? –  Mike conway Oct 24 '11 at 20:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.