开发者

Get Current SPWeb From Web Part

开发者 https://www.devze.com 2023-01-16 01:20 出处:网络
I\'m working on a WebPart, to be used in SharePoint, that will display a listing of documents within a document library. To do so, I believe I need to reference the SPWeb object for which the web part

I'm working on a WebPart, to be used in SharePoint, that will display a listing of documents within a document library. To do so, I believe I need to reference the SPWeb object for which the web part is hosted on. Unfor开发者_JAVA技巧tunately, I don't see how to access the current SPSite or SPWeb from within a WebPart. How would I access these from within a WebPart?


Use the static SPContext.Current property to get access to your SharePoint environment. From SPContext you can get access to both the current SPWeb and SPSite.

SPWeb myWeb = SPContext.Current.Web;
SPSite mySite = SPContext.Current.Site;
0

精彩评论

暂无评论...
验证码 换一张
取 消