views:

106

answers:

1

Hey,

I'm trying to get the GUID of a given sharepoint URL. I don't mind using the API or the webservices or Sharepoint's database.

if i were to write a function, it's signature would be: //get a GUID from path. string GetGuidFromPath(string path){}

I had a lead: SPContentMapProvider but it doesn't seem to get the right info.

Thank you!

+1  A: 

Depends - what's the context of the current request? Is your code running in the context of a SharePoint request? If so you can just use SPContext.Current.Web.ID

Otherwise, is your code at least running on one of the SharePoint servers? If so you'll need to use:

// Given the URL http://mysharepointsite.com/sites/somesite/somesubsite

using(SPSite site = new SPSite("http://mysharepointsite.com/sites/somesite"))
{
    using(SPWeb web = site.OpenWeb("somesubsite"))
    {
        Guid webId = web.ID;
    }

    // Or
    Guid rootWebId = site.RootWeb.ID;
}
zincorp
Thank you for you answer,Let's say my URL is this:http://argentina:94/Lists/Tasks/AllItems.aspxor:http://argentina:94/Lists/Tasks/My%20View.aspxwhich is the same page (with a different view)how would I use the above code?Thank you!!!