Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Finding the doc lib in which a doc lib resides

  Asked By: Hannah    Date: Jan 07    Category: Sharepoint    Views: 980

I have a sharepoint site with more than 1 document library and i need
to find out in which document lib a document resides. Is there any
direct method call through which this can be done, instead of looping
through all the elements of the doc libs ? Also, is there any call
through which we can get the index of an item in the doc lib from its



1 Answer Found

Answer #1    Answered By: Kevin Davis     Answered On: Jan 07

The URL for the document  tells everything. It looks a little like this.:
The domain name, the site  name, the document library  name, the sub
folder names, the document name.

If you what to get the document item  though the object model. Look at
this sample code.

string docUrl = "[the document url]";
SPSite site = new SPSite(docUrl);
SPWeb web = site.OpenWeb();

string folderUrl = docUrl.Substring(web.Url.Length+1);
SPFile file = web.GetFile(folderUrl);
SPListItem item = file.Item;

Context.Response.Write("<p>Item ID "+ item.ID +"<p>");

Didn't find what you were looking for? Find more on Finding the doc lib in which a doc lib resides Or get search suggestion and latest updates.