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
2
votes
1 answer

Dispose of an SPWeb that is being returned from a function

We have code where at times we'll be returning an SPWeb object from a function. So for example: public SPWeb getDeptWeb() { SPWeb deptWeb = SpSite.OpenWeb(SpContext.Web.ID); ... return deptWeb; } How can we dispose of the SPWeb object…
code master
  • 2,026
  • 5
  • 30
  • 49
1
vote
2 answers

Sharepoint: Create a subweb from an item event handler

I have a "project list" (title, lead, members, site-URL) that is supposed to refer to team sites under the site that has the project list. So I added an SPItemEventReceiverto my feature in a sandbox solution to do that. In ItemAdding(properties), I…
1
vote
1 answer

Logical Error foreach Web.webs

I am trying to iterate through each web and its webs, to get the list of child webs and so on, but problem is, when iteration comes to a web which doesn't have any sub webs it gives an exception Object Reference not set to an instance of an…
Muhammad Raja
  • 1,970
  • 3
  • 28
  • 46
1
vote
0 answers

Programmatically Get Disk Usage Of SPWeb Object In Sharepoint 2010 C#

I am trying to figure out how to get the disk space used on a SharePoint Site(SPWeb). I have seen solutions that involve PowerShell or going through all of the libraries and iterating through all of the files to get the total size. However, given…
Algorhythm
  • 570
  • 4
  • 17
1
vote
1 answer

Powershell Sharepoint SPWeb too many items

I am trying to edit a large number of items (>400,000) on a sharepoint list using Powershell and GET-SPWeb. Ideally there would be a way to get only half or a quarter of the items at a time. The following code worked up to 100.000 items, but…
David
  • 11
  • 2
1
vote
0 answers

SharePoint SPWeb.GetList seems to cause infinite loop?

So, I'm working on a SharePoint 2010 site that I developed, and I am trying to implement content type change propogation. During this process I seem to have found a strange bug. It seems my combination of calling methods in the SharePoint object…
TehOne
  • 2,569
  • 3
  • 26
  • 36
1
vote
2 answers

How can i know if a given SPWeb is a SearchCenter site programmatically

I have a SPWeb object and I want to know whether or not this is a SearchCenter site. How can I know it programmatically. Is there some setting to check or a guid to match etc?
Abhinav Dayal
1
vote
1 answer

How do I get the user Id from user information list using the user name with help of javascript?

I have a condition in which I add people to user information list and then would like to add them to a custom list in my site. Using sharepoint search api I was able to get the Preferred Name and am able to add the person to the user information…
1
vote
2 answers

How can I get a SharePoint user profile via the "Friendly Name" using the SP web service?

I'm retrieving a list of names from a SharePoint list in my client program. The names are populated from a name picker in SharePoint. In the XML returned from the list query, the list looks like this: "#10;#Some Name;#12;#Another Name;#15;#Yet…
CMPalmer
  • 8,571
  • 5
  • 40
  • 49
1
vote
5 answers

Programmatically Accessing SharePoint Style Library from within C#

Firstly, I'm a newbie to C# and SharePoint, (less than a month's experience) so apologies if this is an obvious or easy question but I've been trawling the net for a couple of days now with absolutely no success. I have an xslt file that I have…
pwmusic
  • 4,739
  • 4
  • 23
  • 14
1
vote
5 answers

Is possible to inherit from SPWeb?

Is possible to inherit from SharePoint classes such like: SPWeb, SPList etc. or this classes are sealed? I couldn't find right answer. Chris Thanks for replys. Rich, you are right - the constructors are internal. So it means that I coudn't extend…
Chris
  • 103
  • 1
  • 8
1
vote
0 answers

Permission who has no effective permission site user returns "Open" in SharePoint 2013 SP1

I want to check current user which have permission of site, programmable in SSOM. I had created for console application in Visual Studio 2013. but I got funny result in one SharePoint farm. At "Site collection features" section, I had activated…
Blue
  • 41
  • 5
1
vote
2 answers

What is the best practice to save/retrieve site specific (SPWeb) data in SharePoint 2010?

I would like to manipulate certain data objects bound to SPWeb in my SharePoint 2010 Farm. For instance, I am building an application page accessible from a site's settings page that would give the ability to specify a point of contact for a site.…
Jerome P.
  • 45
  • 1
  • 5
1
vote
1 answer

Any other option besides using a this object

I'm create a timer job in sharepoint and have made it quite far. I am running into the issue of having a "this" object in a static method. Here is my code. If anyone has any suggestions, that would be great. public static SPListItemCollection…
user2487016
  • 51
  • 1
  • 3
1
vote
1 answer

How to enumerate all webs and data in a SharePoint site collection

What is the best way to enumerate all SPWebs in an SPSite and also to enumerate folders within document libraries within each of the SPWebs? (essentially I want to find out the urls of all SPWebs, and the number of folders and amount of data being…
Zarek
  • 939
  • 3
  • 13
  • 21