none
how to get complete Document Library url into SPSite object

    Question

  • Hi!

    some documents are in Document Library of sharepoint 2007.

    this url is http://abcd:24931/docu/Forms/AllItems.aspx

    my task is

    i need to display these documents into datagridview of windows form application.

    so, i written SPSite siteurl= new SPSite("http://abcd:24931/docu/Forms/AllItems.aspx");

    but here(while debuging...) siteurl object is does not contain above complete url.

    just it(siteurl) contain only http://abcd:24931, this is my big problem please provide a soluton....

    and i think your understood my task also please provide some idea(coding) about my task.

    thanks & regards

    jilani

     

    Tuesday, September 28, 2010 4:34 PM

Answers

  • On this line

    using (SPWeb web = ospSite.OpenWeb("/docu/Forms/AllItems.aspx"))
    

    don't use "/docu/Forms/AllItems.aspx" but try to get website like

    using (SPWeb web = ospSite.OpenWeb("/subsite"))
    if document library is under root web then just use "/" is enough instead of "/subsite".

    Then use your document library name here

    SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists["Shared Documents"];
    In my case i have used "Shared Documents" document library.

     


    Regards, Sandip Patil, .Net,Sharepoint Developer www.worldofsharepoint.com
    Wednesday, September 29, 2010 10:12 AM

All replies

  • Directly putting above url (http://abcd:24931/docu/Forms/AllItems.aspx) will not give you the collection of documents

    First using SPSite class load site collection then get the website using SPWeb class like 

     

    using (SPSite ospSite = new SPSite("http://abcd:24931"))
    {
     using (SPWeb web = ospSite.OpenWeb("/subsite"))
     {
       // Get document library collection here and fetch all the document urls
     }
    }
    


    Regards, Sandip Patil, .Net,Sharepoint Developer www.worldofsharepoint.com
    Tuesday, September 28, 2010 4:41 PM
  • Hi Patil!

    thanks for replay....

    //Get document library collection here and fetch all the document urls( need coading)

    please provide full coding because i traid a lot.....

    thanks & reagrds

    jilani

     

    Tuesday, September 28, 2010 5:21 PM
  • using (SPSite ospSite = new SPSite("http://abcd:24931"))
    {
     	using (SPWeb web = ospSite.OpenWeb("/subsite"))
     	{
      		// Get document library collection here and fetch all the document urls
    		SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists["Shared	Documents"];
    		SPListItemCollection items = docLib.Items;
    
    		foreach (SPListItem item in items)
    		{
    			string url = item.Url;
    		}
     	}
    }
    
    

    Regards, Sandip Patil, .Net,Sharepoint Developer www.worldofsharepoint.com
    Wednesday, September 29, 2010 2:45 AM
  • still i am getting same problem.......

    using (SPSite ospSite = new SPSite(http://abcd:24931))   ----->output is not respond
    {
    using (SPWeb web = ospSite.OpenWeb("/docu/Forms/AllItems.aspx"))
    {
      // Get document library collection here and fetch all the document urls
    SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists["docu"];  //where docu is my  document library
    SPListItemCollection items = docLib.Items;

    foreach (SPListItem item in items)
    {
    string url = item.Url;
    }
    }
    }

     please help me...

     

    Wednesday, September 29, 2010 9:53 AM
  • Sandip's response is correct - you should use the code Sandip provided, if you still receive an error when trying to create the SPSite object then can you confirm you are running your Windows Forms application on the SharePoint server?

    In order to use the SharePoint object model, the code must be running on the actual SharePoint server, and not a client computer. Should you want to communicate with SharePoint from a client computer then you should use the web services provided to do exactly this.


    Read my wiki at www.intheknow.it for more code and tips for developing with SharePoint 2007 & 2010
    Twitter: @starznet

    Technical Architect at Starznet Ltd. WSS/MOSS development and customisation with a primary focus on CMS.

    • Edited by Stuart Starrs Wednesday, September 29, 2010 10:10 AM made answer clearer
    Wednesday, September 29, 2010 10:06 AM
  • On this line

    using (SPWeb web = ospSite.OpenWeb("/docu/Forms/AllItems.aspx"))
    

    don't use "/docu/Forms/AllItems.aspx" but try to get website like

    using (SPWeb web = ospSite.OpenWeb("/subsite"))
    if document library is under root web then just use "/" is enough instead of "/subsite".

    Then use your document library name here

    SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists["Shared Documents"];
    In my case i have used "Shared Documents" document library.

     


    Regards, Sandip Patil, .Net,Sharepoint Developer www.worldofsharepoint.com
    Wednesday, September 29, 2010 10:12 AM
  • thanks for your replay...

    please keep touch with me...

    thanks & regards

    jilani

     

     

    Wednesday, September 29, 2010 10:22 AM
  • Hi!

    my task this..

    some documents are in Document Library of sharepoint 2007.

    this url is http://abcd:24931/docu/Forms/AllItems.aspx

    my task is

    i need to display these documents into datagridview of windows form application.

     

     

    Wednesday, September 29, 2010 10:31 AM
  • haaaasscvb

     

    here what is

    using (SPWeb web = ospSite.OpenWeb("/subsite"))

                                                                   |--------->here what is  subsite

     

     

    Wednesday, September 29, 2010 10:33 AM
  • If your document library is at root level then you can use

    using(SPWeb web = ospSite.RootWeb)

    {

              //your code

    }

     

    hope this helps

    Wednesday, September 29, 2010 10:38 AM
  • Hi sandip!

    still it is not working by using above code....

    i think  Alternate Access Mappings (AAM) concept is required..

    can u suggest to me how can i add this AAM to my url.

    thanks & regards

    jilani

     

     

     

    Wednesday, September 29, 2010 2:54 PM
  • Wednesday, September 29, 2010 3:17 PM
  • Can you confirm you are executing your code on the physical SharePoint server, and not trying to access the SharePoint site remotely - if not then your problem is not with the URL's or AAM. Can you browse to the site using the URL with Internet Explorer correctly?


    Read my wiki at www.intheknow.it for more code and tips for developing with SharePoint 2007 & 2010
    Twitter: @starznet

    Technical Architect at Starznet Ltd. WSS/MOSS development and customisation with a primary focus on CMS.
    Wednesday, September 29, 2010 3:37 PM
  • Hi!

    thanks for ur replay.

    http://abcd:24931/docu/Forms/AllItems.aspx it is my actual sharepoint 2007 web address.

    and my documentary library name is docu.

    when iam copy & past into internet browser of my system it is perfetly working.

    but it is not access to spsite obj1= new spsite(); of my windows forms application.

    i had tried in this way

    using

     

     

    (SPSite oSite = new SPSite("http://abcd:24931"))

              {

     

     

                  using (SPWeb oWebsite = oSite.OpenWeb("/docu/Forms/AllItems.aspx "))

                     {

     

     

                      using(SPWeb oWebsiteRoot = oSite.RootWeb)

                            {

     

     

    SPDocumentLibrary docLib = (SPDocumentLibrary)oWebsiteRoot.Lists["docu"];

     

     

    SPListItemCollection items = docLib.Items;

     

     

    foreach (SPListItem item in items)

    {

     

     

    string url = item.Url;

    }

    }

    first statement itself not responding to output

    i tried this one also like

    using (SPSite oSite = new SPSite("http://abcd:24931"))

              {

     

     

                  using (SPWeb oWebsite = oSite.OpenWeb("/docu "))

                     {

    same thing.....

    plese help me....

    plese try this one inyour system.

    please send proper idea for me.

    thanks& regards

    jilani

    plese contact to me 91+9886711749

     

     

    Thursday, September 30, 2010 8:17 AM
  • Hi!

    thanks for ur replay.

    http://abcd:24931/docu/Forms/AllItems.aspx it is my actual sharepoint 2007 web address.

    and my documentary library name is docu.

    when iam copy & past into internet browser of my system it is perfetly working.

    but it is not access to spsite obj1= new spsite(); of my windows forms application.

    i had tried in this way

    using

     

     

    (SPSite oSite = new SPSite("http://abcd:24931"))

     

     

                  using (SPWeb oWebsite = oSite.OpenWeb("/docu/Forms/AllItems.aspx "))

     

     

                      using(SPWeb oWebsiteRoot = oSite.RootWeb)

     

     

    SPDocumentLibrary docLib = (SPDocumentLibrary)oWebsiteRoot.Lists["docu"];

     

     

     

    SPListItemCollection items = docLib.Items;

     

     

     

    foreach (SPListItem item in items)

     

     

    string url = item.Url;

    }

    }

    first statement itself not responding to output

    i tried this one also like

     

    using (SPSite oSite = new SPSite("http://abcd:24931"))

     

     

                  using (SPWeb oWebsite = oSite.OpenWeb("/docu "))

                     {

    same thing.....

    plese help me....

    plese try this one inyour system.

    please send proper idea for me.

    thanks& regards

    jilani

    plese contact to me 91+9886711749

              {

     

    {

     

                            {

     

                     {

     

              {

     

    Thursday, September 30, 2010 8:25 AM
  • This helped me immensely, Sandip you rock!!
    Friday, October 29, 2010 8:22 PM