Sharepoint Forum

 
Home » Forum » Sharepoint       Ask a questionRSS Feeds

Finding the doc lib in which a doc lib resides

  Asked By: Hannah Foster         Date: Jan 07, 2010      Category: Sharepoint      Views: 279
 

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
name.

Tagged:              

 

1 Answer Found

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

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.
E.g.:
mydomain/.../mydocument.doc

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.


Your Answer
  • Answer should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].