Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Webpart relationship with site

  Asked By: Yasasvi    Date: May 18    Category: Sharepoint    Views: 865

I'm attempting to code a webpart (in C#) that displays different
information according to the Sharepoint site that it is displayed on.
For this I need to find the SPSite GUID but I can't seem to find a
relationship between the WebPart and the SPSite class which contains the
GUID. Does anyone have any idea on how to obtain this?



3 Answers Found

Answer #1    Answered By: Tiara Gross     Answered On: May 18

Keep in mind that SPSite refers to the site  collection, SPWeb refers to an
individual site within the collection. The following code  should get you what
you need:

SPWeb mySite = SPControl.GetContextWeb(Context); // gets the current site
SPSite mySiteCollection = SPControl.GetContextSite(Context); // gets the current
site collection

Answer #2    Answered By: Frankie Figueroa     Answered On: May 18

SPControl.GetContextWeb(Context) returns an SPWeb object and I'm fairly
sure you should be able to then get what you need from there...

For example to return the URL of the page a Web Part is in I would use:-

String _currentWeb = SPControl.GetContextWeb(Context).Url.ToString();

Answer #3    Answered By: Wesley Myers     Answered On: May 18

how to get site  section??????????????

Didn't find what you were looking for? Find more on Webpart relationship with site Or get search suggestion and latest updates.