Tag Info

Hot answers tagged

21

Absolutely, if you have SPContext.Current, you don't need to dispose any objects inside. The point is, that SPContext.Current is binded to a SPRequest object, which represents current web page request. So basically, if you will dispose SPContext.Current.Web in your code, it will no longer be available for any other pending code. But, if you will create your ...


21

James and Toni are absolutely correct but have missed the obvious IMHO - your code has a deeper flaw and if you fixed this then disposing the objects is not required. You should (where possible) use the SPWeb and SPSite objects from SPContext - they are already created for you by the SharePoint web part infrastructure and its more efficient to use these ...


11

Yes, you will need to dispose SPWebs created through SPSite.OpenWeb(). To dispose of it, simple call web.Dispose() when you're done in the method. You could also use the Using statement to the same effect, without needing to directly call Dispose() Using site As New SPSite(SPContext.Current.Web.Url) Using web As SPWeb = site.OpenWeb() ...


9

IF you get the SPWeb from the Context, it has been created elsewhere, and that elsewhere will destroy it for you. If you destroy (Dispose) it too early, when the page comes to Dispose of it, it'll most likely panic, and some data used to generate the page will probably be lost. Rule of thumb - if you use SPSite.OpenWeb() or otherwise use new SPWeb(), then ...


6

In IE (version > 6) SignOut.aspx uses ClearAuthenticationCache as a client side command. This does not work for Firefox. I found this example on StackOverflow that might work for you http://stackoverflow.com/questions/31326/is-there-a-browser-equivalent-to-ies-clearauthenticationcache


6

http://msdn.microsoft.com/en-us/library/ff458385.aspx: {SiteUrl} – The fully qualified URL to the site (Url). The SharePoint code proves it - here's the SPCustomActionElement.ReplaceUrlTokens method: internal static string ReplaceUrlTokens(string urlAction, SPWeb web, SPList list, SPListItem item) { if (string.IsNullOrEmpty(urlAction)) ...


5

I am getting up to speed with SharePoint development as well and found Dispose Patterns By Example to be a great reference on this subject. Hope this helps you as much as it's helped me.


5

The Dispose() method if the IDisposal interface is a specifc interface that is used when object locks heavy and expensive resources. For instance when you're acquiring a connection to a database. The Dispose method is there to tell the object that I'm done with the connection (in the Sql case) and that you can now close it and let someone else use the ...


4

If you are in doubt as to whether or not you are handling the dispose correctly, Microsoft has the SPDisposeCheck tool available to check it for you. You can run this manually, directly from Visual Studio or even incorporate it into the validation on your build server.


3

It would be cool if you posted the offending code and its surroundings, but some things to consider out of the top of my head: You might be getting the object too early in the lifecycle (say PreInit methods and such, or an HttpModule etc) You might be breaking the pipeline doing things like setting the HttpContext to null (I've seen that in SharePoint ...


3

Workflows do not have an SPContext so SPContext.Current will always be null. In order to do what you appear to be trying to do, you may have to open the site once as the AppPool account to get the user token then release the site. Then open it again using the token like you are doing now. Something like this : SPUserToken token = null; using (SPSite ...


3

Using {SiteUrl} token is nice, thanks to Alex Boev. Just to mention an alternative, you can use SharePoint javascript API to get the web url. In your example you want to open an application page (from layouts folder). There is a helper function for doing that getLayoutsPageUrl: SP.Utilities.Utility.getLayoutsPageUrl('myPath/EditWebInfo.aspx') So your ...


2

Arrrrrgh! Finally figured it out after messing with this for a good day. I want to leave this here just in case anyone else runs into the same problem. When I register the Javascript endpoint, I use the full URL of the service. So if the root of my site is at: http://mydomain.com/sites/site1 I register it at: ...


2

Another reason for using the SPContext.GetContext is to set the context of a control to one that is different than the context of the current page. For example, you can set the ItemFieldIterator.ItemContext proprty to get information from a list on different SPWeb object. myItemFieldIterator.ItemContext = SPContext.GetContext(Context, 0, ListId, oSPWeb);


2

No, there will not be an error. I commonly use this design pattern to keep my using blocks small. SPList list; using (SPWeb web = SPContext.Current.Site.OpenWeb("myweb")) { list = web.GetList("/myweb/Lists/Awesome Name"); } SPListItemCollection items = list.Items; If you are updating an SPListItem in a manner that requires SPWeb.AllowUnsafeUpdates = ...


2

As far as I know, changing field type from text to lookup is not supported in Sharepoint. You should create new lookup field in the Attendees list and point it to Events list, either from Sharepoint list settings, or from code. Basically, lookup field has the same structure as user field, which you populated in the final bit of your code - ID#;Title. Also, ...


2

The L_Menu_BaseUrl variable is what you are looking for. SharePoint stores the current web url in it. Have a look here: http://vrdmn.blogspot.in/2011/08/javascript-lmenubaseurl-varaible-for.html Also some additional info on other OOB JavaScript Objects: _spPageContextInfo.webServerRelativeUrl will also give you the current web url. ...


2

In addition to the method with determining ContentType in custom ListFieldIterator from query string, ItemContext contains property ContentType. But this property is internal and therefore could not be used directly in custom ListFieldIterator implementation. Below is presented wrapper for retriving ContentType based on corresponding property for SPContext ...


2

I managed to get this working using promises, code below: var queryItems = function(myContext, myDocName, mySelector) { var dfd = $.Deferred( function() { var inContxt = myContext, inDoc = myDocName, myCtx = new SP.ClientContext(inContxt), myList = myCtx.get_web().get_lists().getByTitle(inDoc), ...


2

You actually need to generate a SP.ClientContext for the app web and a SP.AppContextSite for the host web. To get a reference to a list in the host web, try the following: // Get the ClientContext for the app web clientContext = new SP.ClientContext.get_current(); // Use the host web URL to get a parent context - this allows us to get data from the parent ...


2

Any reason why you are not using a HideCustomAction? Here is the MSDN for that. And here is a resource for finding the correct groups


2

What about that? $('.s4-ctx').css('display','none'); It will hide buttons that show context menu. If you need to hide context menu only from web part with specified id you need to use: $("div[webpartid='85c13a33-57a3-456b-a19b-c68c97756184'] .s4-ctx").css('display','none'); If you want to remove menu item, for ex. "Alert Me" add this script that ...


1

I'm wondering if you aren't actually suffering from the pretty well-known problem as described by Waldek (http://blog.mastykarz.nl/inconvenient-spweb-getlistitem-exception-hresult-0x80070001/) which is due to the way the GetListItem is implemented and the URL that receives as parameter. For the 2nd problem (where you attempt using the SPContext after ...


1

plz try with this.. SPWeb spWeb = Microsoft.SharePoint.WebControls.SPControl.GetContextWeb(System.Web.HttpContext.Current); SPUser user = spWeb.CurrentUser; or using (SPSite spsite = new SPSite(url)) { using (SPWeb spweb = spsite.OpenWeb()) { userObj = spweb.CurrentUser; ...


1

is the link to your application page pointing to http://sharepointserver/dev/_layouts/test.aspx or is the link to your application page pointing to http://sharepointserver/_layouts/test.aspx It should be the first if is the second this will explain your problem. if not then the question will be is dev/ as sub site or a managed path site collection ?


1

Check this link... You need to get the web applications first then iterate through each web application's sites. Can't this be a web applicatiion feature? Why exactly would you make it a farm feature?


1

Got it, had to provide the context in the init params of my object tag. <object id="SilverlightPlugin1" width="400" height="300" data="data:application/x-silverlight-2," type="application/x-silverlight-2" > <param name="source" value="/content/SilverlightApplication1.xap"/> <param name="initParams" ...


1

You are correct, never dispose an object retrieved from a Property from SPContext. The simple reason being, you can never be sure that there is another thread, control or other piece of code that executes after your code does and is expecting that properly to exist. Your first two examples (where you put one versus the other) are functionally identical, ...


1

Some time ago I attempted to do this and determined that to programmatically remove a Firefox log-in without the browser you had to do some crazy stuff like clearing cached credential info from the computer as well as standard web request removals, and had to assume the user would have the trust on the site set so that it would allow it. Ultimately I ...


1

On a standard list form if an attachment with the same name was added multiple times. If the item will be stored the form throws an exception, that one of the attachments was added multiple time and prevent from adding the item. In your case you override this exception, which causes that no attachments are available when you try to store the list item. To ...



Only top voted, non community-wiki answers of a minimum length are eligible