Questions tagged [spweb]

Represents a SharePoint Foundation website.

Definition:

An SPWeb object represents a single website in SharePoint residing in a Site Collection (SPSite).

More reading:

Code example:

//through current context
SPWeb myWeb = SPContext.Current.Web;

//opening from an SPSite
SPWeb mySite = mySiteCollection.OpenWeb("http://yoursiteurl/"))

SPWeb implements the IDisposable interface so you should close the object when you no longer need it. This is not the case when you're object is assigned through a Context. So in the first line, the Dispose() should not be called. You can close it manually or use the using statement to do this for you:

//manually
myWeb.Dispose();

//using statement
using(SPSite mySiteCollection = new SPSite("http://mysharepointsite/"))
{
    using(SPWeb myWeb = mySiteCollection.OpenWeb("http://yoursiteurl/"))
    {
        //get the title of the website
        string name = myWeb.Title;
    }
}
45 questions
14
votes
6 answers

Best Pattern for AllowUnsafeUpdates

So far, in my research I have seen that it is unwise to set AllowUnsafeUpdates on GET request operation to avoid cross site scripting. But, if it is required to allow this, what is the proper way to handle the situation to mitigate any exposure?…
webwires
  • 2,572
  • 3
  • 26
  • 44
12
votes
1 answer

How to get SPWebApplication from SPWeb?

So I'm inside a web scroped feature (properties.Feature.Parent = SPWeb). How do I get the SPWebApplication from this SPWeb? I tried: SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent; But of course I get an exception because I…
Dennis G
  • 21,405
  • 19
  • 96
  • 133
6
votes
3 answers

Should I dispose of this SPWeb?

I'm hoping someone can help me out. I need to get the root web of the current site from the SPContext. It's easily done with the following SPContext.Current.Site.RootWeb I'm comfortable with the idea that the SPSite object here at…
Mark
  • 487
  • 1
  • 7
  • 20
5
votes
2 answers

SharePoint, how do you programatically determine the storage size of a SPWeb?

Not of the site collection itself, but the individual SPWeb's.
Shane Jordan
5
votes
1 answer

What is the difference between SharePoint Web and Site

Could anybody explain the difference between SP.Web and SP.Site entities? As I understand SP.Site contains different SP.Webs, that represent SiteCollections. Is it correct? Could you please share any links for better understanding this approach?
Warlock
  • 7,321
  • 10
  • 55
  • 75
5
votes
1 answer

Get files from _layouts folder in SharePoint

I'm currently working on a project where I'm adding docx-files to the Layout folder in Visual Studio and then use those ducment files to create Content Types. The problem is that I can't get the document files programmatically. Using the web browser…
carruw
  • 361
  • 5
  • 10
  • 21
4
votes
1 answer

CouchDB: Single Page Web Application accounts without middleware

Is it possible to implement Single Page Web Application that would have sensitive data, e.g. accounts, with address etc, without middleware? I've been evaluating CouchDb, as the best applicable, because it allows to implement author only updates.…
avalez
  • 1,217
  • 1
  • 10
  • 15
4
votes
1 answer

Using disposed SPSite and SPWeb objects

I was happy enough to have inherited a terribly written SharePoint project. Apparently, the original developer was a big fan of reusable code (30% of code is reused across 20 projects without using any libraries—guess how?). I would often find his…
Dan Abramov
  • 264,556
  • 84
  • 409
  • 511
4
votes
3 answers

Memory Leak in SharePoint Code?

I am just wondering how to find out a memory leak in a code. I am working on a code written by someone else and been told that it has a memory leak. I am going through the code to see if it has a memory leak. does following code has memory leak.…
user388969
  • 337
  • 1
  • 9
  • 30
4
votes
2 answers

How do I programatically turn off show pages in navigation for sharepoint

I am progamatically creating a SharePoint site using SPWeb spWeb = spSite.AllWebs.Add(...); What code do I need run to set the spWeb to turn off the "Show pages in navigation" option? Answer: publishingWeb.IncludePagesInNavigation = false;
Nat
  • 14,175
  • 5
  • 41
  • 64
4
votes
2 answers

SPWeb.Url returns wrong URL

I have a web application in SharePoint that has been extended to another zone (Extranet). The access URL for the default zone is http ://server1, and the URL for the extranet zone is https: //www.server1.com. Now, when I access the site via the…
Jason
  • 41
  • 1
  • 2
3
votes
1 answer

Keep the same SPWeb & SPSite through the whole application lifecycle?

We have several projects with many DAL. Many sharepoint lists like customers, sells, providers which reflect in C# classes. We make each object implement IDisposable through an abstract mother class. And each time we instantiate an object to get a…
KitAndKat
  • 953
  • 3
  • 14
  • 29
3
votes
2 answers

Impersonate user programmatically on Sharepoint 2013 (C#)

This might an odd question, but what I would like to achieve is a functionality that would allow specific users to view SharePoint pages as if they were logged in as different users. Let's say we have a Student page and a Staff page. I am not a…
Naner
  • 1,292
  • 6
  • 25
  • 43
2
votes
2 answers

Get SPWebTemplate from SPWeb

In my PowerShell script, I want to get the SPWebTemplate which has been used to create a SPWeb. In SPWeb instances, properties WebTemplate and WebTemplateId are accessible, but both of them dont identify a SPWebTemplate uniquely. For example, if the…
Jonas W
  • 373
  • 1
  • 4
  • 15
2
votes
4 answers

Capturing title change event on SPWeb

I am listening on a particular SPWeb using an SPWebEventReceiver that is successfully firing on the WebMoved event. When the web is moved I update a list with the new location/title. What I would like to be able to do is listen for when the Web is…
Steve Ruiz
  • 259
  • 1
  • 3
  • 12
1
2 3