Represents the context of an HTTP request in Microsoft SharePoint Foundation.

learn more… | top users | synonyms

25
votes
1answer
20k views

Using SPContext.Current or using static URL

There are multiple ways to work in the SP object model. The starting point for instantiating objects looks different when you look at different developers. Many times I see people doing this: SPList ...
11
votes
3answers
2k views

Should I dispose these SPSite and SPWeb objects?

Is it necessary to dispose the site and web objects in the following code? If so, how do I do this? Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load Dim site ...
9
votes
4answers
1k views

Disposing and Closing SPWeb objects

I have used something like using (SPWeb web = SPControl.GetContextWeb(Context)) but while deploying the project it shows an error. While trying to figure out the cause I came across an msdn ...
7
votes
4answers
339 views

How do I get machine name off of the SPContext

Simple question... how do I get the machine name off of the SPContext object.
5
votes
4answers
8k views

Get current web url in a SPRibbon Custom Action Command

I've a SPRibbon custom action with the purpose of open an custom app page in a modal dialog, but I'm getting troubles for getting the current web URL, as well, set a reference for a .js with the right ...
5
votes
6answers
1k views

SharePoint 2007 : How to sign out user?

I've an application build on SharePoint 2007 platform, the problem is in Mozilla FireFox, the sign out button does not successfully sign out the current login user, I believe SharePoint 2007 is not ...
5
votes
1answer
3k views

SPContext.Current is NULL for IHttpHandler

I am trying to implement IHttpHandler in SharePoint 2010 and for reference I am using this: http://blogs.msdn.com/b/kaevans/archive/2010/08/04/deploying-an-asp-net-httphandler-to-sharepoint-2010.aspx ...
5
votes
4answers
2k views

Custom Sign In Page has an SPContext.Current that is always null

Found the Solution The solution was to add a Root Site Collection (as the code was running in a sub-site, without a root site). See This Solution Important Update (based on ...
5
votes
2answers
951 views

Why does the FileUpload control get bound to the current list item in a custom list EditForm?

I've written a custom edit form for a list which means I lose certain out of the box capabilities such as Attachments as it was part of the out of the box form. The way I have implemented the form is ...
3
votes
2answers
2k views

SPContext.Current vs SPContext.GetContext

To get current SP objects (SPWeb, SPSite, SPList etc), I generally use SPContext.Current. In some situations, SPContext.GetContext is preferred because SPContext.Current have many objects null ...
3
votes
1answer
2k views

Is SPContext.Current Supposed to Be null in Custom WCF Service?

Here is the scenario: Custom WCF Service deployed in SharePoint 2010 Site is using Claims Based authentication (FBA, NTLM) .svc is deployed to ISAPI in the hive Service is configured using custom ...
2
votes
1answer
340 views

What is difference between httpcontext and spcontext?

We always use SpContext.Current.Web, but then what is difference between httpcontext and spcontext?
2
votes
3answers
3k views

Is there an alternative to SPContext.Current.Web.CurrentUser?

I have found that SPContext.Current.Web.CurrentUser is really unreliable. One out of ten requests that object comes back as null. Is there an alternative to SPContext.Current.Web.CurrentUser? Has ...
2
votes
3answers
2k views

How to get full home page address of a site collection?

When I use SPContext.Current.Site.Url it returns "http://servername" I need the full homepage URL which is "http://servername/SitePages/Home.aspx" Does anyone know how to get this programmatically?
2
votes
1answer
3k views

Accessing a list from app web on host site generates access denied

I am trying to get title of a list which is located on Host Site from an SharePoint hosted app by using csom (javascript). I have added permission on Manifest file and chose the list but still getting ...
2
votes
1answer
93 views

Start workflow using App only client context

I use CSOM with client contex which I get from app, the App has following permissions: <AppPermissionRequests AllowAppOnlyPolicy="true"> <AppPermissionRequest ...
2
votes
1answer
700 views

Calling SP.ClientContext in a loop Javascript

I'm looping through a number of sites to run a query that checks whether new content has been added to document libraries in that site in the previous three days. However, I'm having problems. When I ...
2
votes
2answers
725 views

How to determine item ContentType in FormControl (FieldIterator for instance)?

I've implemented my ListFieldIterator to change the way field controls rendered. I'd like to change the behaviour of form depending on the item content type, but any attempts to determine ...
2
votes
1answer
266 views

Will using a `SPList` object derived from a disposed `.OpenWeb()` cause errors?

Will using a SPList object derived from a disposed .OpenWeb() cause errors? SPList list = null; using (SPWeb web = SPContext.Current.Site.OpenWeb("/myweb")){ list = web.Lists["Awesome Name"]; } ...
2
votes
1answer
41 views

Missing properties of _spPageContextInfo after page load

I have a script that provision site collections under a specific managed path. In these site collections, I have sub webs with page libraries in which I have several different pages with custom ...
2
votes
1answer
82 views

Create context for another site collection using NAPA

I am trying to access another site collection using NAPA. I found 2 ways, none of which seem to be working Office 365- Accessing lists refers wrong URL (URL/App name) var context = new ...
2
votes
2answers
1k views

Life cycle of SPContext.ListItem

I have created a messaging system (basically a simple announcement list with a recipient and a IsRead flag). This have been done by creating the classics web fields, content type, list schema and ...
1
vote
3answers
2k views

sharepoint 2010 context menu event handler

i want to hide sharepoint 2010 list/library context menu based on users. i am using below javascript $(document).ready(function(){ $('.ms-MenuUIPopupBody').live('blur', function() { ...
1
vote
1answer
455 views

clientContext is always null in Provider Hosted App

I am following this article- http://chakkaradeep.com/index.php/building-apps-for-sharepoint-with-mvc/ to learn building Provider Hosted Apps in SharePoint. I have one developer site collection (I am ...
1
vote
1answer
36 views

SPContext.Current.Web.CurrentUser returns wrong user (Broken user database?)

This code snippet is used to Break Role Inheritance on a Document Library and set the current user as the only user who has "Read" priviliges on that Library: SPUser oUser = ...
1
vote
1answer
1k views

SharePoint Foundation 2013 - Problem with loading sp.js and sp.runtime.js

I have problem with an order in which I am loading <script type="text/javascript" src="/_layouts/15/sp.js"></script> <script type="text/javascript" ...
1
vote
1answer
475 views

Web.GetListItem with a non list URL breaks SPContext

We have a bit of a weird issue and i was wondering if anyone had any insight on why the issue was occurring. We have a page deployed into the SharePoint root which has a custom webpart which would ...
1
vote
3answers
283 views

SPWeb = this.Web always points to Central Administration?

I'm learning SharePoint 2010 and facing a strange problem : I implement a custom action to add a ribbon button under Documents tab, this button has a command to open a modal dialog in my site which ...
1
vote
2answers
763 views

SPContext.Current is sometimes null in code behind of InfoPath

On occasion I find that SPContext.Current returns null in the code behind of my InfoPath forms. This is occuring while I have the form open in a SharePoint 2010 site collection. I can't figure why ...
1
vote
1answer
593 views

ClientContext error while embedding a Silverlight control on ASP page

I build a visual web part in asp.net and I'm trying to embed a xap over it so that users who don't have Silverlight installed would see the asp content: <object id="SilverlightPlugin1" ...
1
vote
0answers
30 views

FormContext.FormMode == DISPLAY after calling Edit Item in custom list

In a custom webpart we check on PageLoad the SPContext.Current.FormContext.FormMode to show different additional controls on edit and display mode. If the list is created manually everything works ...
1
vote
0answers
89 views

SPContext.Current is null

I am making a call to a Web service on the initial load of the page through an Angular JS Service. The Web service calls a DLL where I am accessing SPContext.Current. If I am allowing the application ...
1
vote
2answers
92 views

When to call Dispose if passing SPContext.Site to a class library?

I'm just looking for a bit of sanity check on this one! I'm looking at many classes that have SPSite or SPWeb as a constructor for the class. The class is instantiated using SPContext.Site as the ...
1
vote
2answers
1k views

Get SPWeb from SPContext in WCF hosted on SharePoint

I have created and deployed a WCF service in SharePoint and I am sending requests using JQuery. Every thing is working fine except for sub sites. Lets say I have these two service URLs: - ...
1
vote
0answers
561 views

Fake SPContext as a particular user

I am using this method of faking an SPContext: http://solutionizing.net/2009/02/16/faking-spcontext/ public static SPContext FakeSPContext(SPWeb contextWeb) { // Ensure HttpContext.Current if ...
0
votes
2answers
4k views

What is difference between SPContext.Current.Web.URL and SPContext.Current.Site when using SPSite object?

SPSite spsite1=new SPSite(SPContext.Current.Web.URL); SPSite spsite2=SPContext.Current.Site; What is the difference and when do we decide which one to use? I feel both give us the site collection ...
0
votes
2answers
3k views

Error using SPContext.Current.Web.AllUsers in Visual Studio workflow

I have the following code running in a Visual Studio workflow. I am trying to specify the user who is adding list items in the code because I guess the system account (default for VS) will not allow ...
0
votes
1answer
281 views

Setting a Lookupfield for current Item in List

my use-case: I'm trying to implement an event-management system to sharepoint using visual web part(s). I have two custom lists, one is called "events". Let's say it has a column "Title" which shows ...
0
votes
1answer
100 views

Why is IsCurrentUserMemberOfGroup throwing an exception when run on SPSite.RootWeb?

Running this code in PowerShell (or even in a web context in C#) gives an unexpected behavior: Calling IsCurrentUserMemberOfGroup directly on the RootWeb object gives an exception, and worse: it ...
0
votes
1answer
406 views

Get Context through REST call

I know that in SharePoint 2013 with JavaScript, you can load the current context like so... var context = SP.ClientContext.get_current(); var user = context.get_web().get_currentUser(); ...
0
votes
1answer
807 views

SPWeb.GetList issue on SPContext.Current.Web

When I call SPContext.Current.Site.RootWeb.GetList(someListUrl) I get a System.Runtime.InteropServices.COMException, but when I call the same method from a new SPWeb instance, it runs fine - why? // ...
0
votes
2answers
2k views

Getting page title in page layout

I am using the following code to get page title of current page in Page Layout but it is not working. <asp:Literal runat="server" ...
0
votes
2answers
97 views

Accessing list from variation

I retrieve all the lists in the current web using: foreach (SPList list in SPContext.Current.Web.Lists) {} This works well. The problem is that when a user changes languages, and is routed to the ...
0
votes
1answer
299 views

Grab list of site collections from SPFarm object

I have a Farm level feature that returns null when I try to access SPContect.Current.Site. Is another way to grab a list of site collections? I have access to SPFarm.Local
0
votes
1answer
802 views

Proper use of SPWeb from SPContext for pulling lists

So, after about two hours on the subject I am thoroughly confused. There are viewpoints all over the place on how, when, and why to use Dispose() on SPWeb objects as they relate to SPContext. Can ...
0
votes
2answers
3k views

What is the most effecient way to get the current server name?

I need to determine the 'main' server name based on the My Site server name in a control. This control needs to work in multiple environments with a different set of servers in each. Example: My ...
0
votes
3answers
699 views

SPContext returns wrong user account [closed]

I'm creating a web part on a non local server and I need to get the current user logged in to SharePoint. I'm using the following code to get the username. string currentUser = ...
0
votes
0answers
25 views

SPServiceContext is null exception when I try to create result source in farm feature receiver

I created an feature farm scoped. In the eventreceiver of this feature I would like to create a new custom "result source". When I try to deploy I got an exception in VS: Value cannot be null. ...
0
votes
0answers
61 views

How to get Groups RoleAssignments with COM

I'm trying to retrieve Roles Assignments and SPRoleDefinitionBindingCollection from a Group .Probably, I'm using the wrong method to that. The RoleAssignment groupRoleAssignments = ...
0
votes
0answers
120 views

Current user in custom WCF REST service hosted in SharePoint consumed by Workflow 2013

I have a custom WCF REST service hosted in SharePoint. It is configured by MultipleBaseAddressWebServiceHostFactory in .svc file: <%@ ServiceHost Language="C#" Debug="true" ...