none
how to find document item id if knowing file name by CAML query? RRS feed

  • Question

  • I need to find the item id in a document library by CAML query? The only information I knew is file name.

    I tried several fields as from googe search, none works in U2U CAML query tool: FileLeafRef, FileLinkname, FileLinknameNoMenu,...

    Any ideas would be appreciated,

    Thanks, Guangming

    Wednesday, June 30, 2010 8:13 PM

Answers

  • Try this.

    SPList list = web.Lists["MyDocName"];
    SPQuery dQuery = new SPQuery();
    dQuery.ViewAttributes = "Scope=\"Recursive\"";
    string QueryString = "<Where>" +
                     "<Eq>" +
                       "<FieldRef Name=\"FileLeafRef\"/>" +
                        "<Value Type=\"Text\">" + fileName + "</Value>" +
                     "</Eq>" +
                    "</Where>";
    dQuery.Query = QueryString;
    SPListItemCollection collListItems = list.GetItems(dQuery);
    

    Oleg

     

     

    • Marked as answer by Guangming Friday, July 2, 2010 12:01 PM
    Wednesday, June 30, 2010 8:31 PM

All replies

  • Try this.

    SPList list = web.Lists["MyDocName"];
    SPQuery dQuery = new SPQuery();
    dQuery.ViewAttributes = "Scope=\"Recursive\"";
    string QueryString = "<Where>" +
                     "<Eq>" +
                       "<FieldRef Name=\"FileLeafRef\"/>" +
                        "<Value Type=\"Text\">" + fileName + "</Value>" +
                     "</Eq>" +
                    "</Where>";
    dQuery.Query = QueryString;
    SPListItemCollection collListItems = list.GetItems(dQuery);
    

    Oleg

     

     

    • Marked as answer by Guangming Friday, July 2, 2010 12:01 PM
    Wednesday, June 30, 2010 8:31 PM
  • This does work by codes, even not in the U2U tool. Thanks,
    Friday, July 2, 2010 12:01 PM