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

Add RoleAssignment Member to SPItem Using PowerShell

I will be executing a script to remove permissions from a SPitem. However, a rollback plan is required and I am required to create a separate script which will add the permission of the user back to the SPitem if required. Below is my code snippet…
gymcode
  • 4,431
  • 15
  • 72
  • 128
0
votes
1 answer

SPWeb.GetItems Does not Retun Folder Type items

I retrieved all items in my SharePoint list using .GetItems() command. However, it does not have contain folder type items in my result. A type of ERMS Folder Content Type do exists in the list, as below: Documents of other content types are still…
gymcode
  • 4,431
  • 15
  • 72
  • 128
0
votes
3 answers

SPWeb.GetFolder Unable to Pass String Value In

I am unable to pass a string value into my SPWeb.GetFolder despite my input being a string value. private static void UploadEmlToSp(string sharePointSite, string sharePointDocLib, string emlFullPath, string requestNo) { using (SPSite oSite = new…
gymcode
  • 4,431
  • 15
  • 72
  • 128
0
votes
2 answers

SPWeb.GetListItem COMException on first call - second is ok

I'm trying to use SPWeb.GetListItem() to get an item by a known URL (MSDN). So basically I'm doing the following: using (SPSite spSite = SPContext.Current.Site) { using (SPWeb spWeb = spSite.RootWeb) { SPListItem spListItem =…
Dennis G
  • 21,405
  • 19
  • 96
  • 133
0
votes
1 answer

SharePoint 2013 - Getting SPSite.Url from SharePoint DB

I'm working directly against the SharePoint DB (I know it is highly not recommended but I need to, for several reasons). I'm trying to get the SPSite.Url property ("http://baseurl/sites/somename") but can't figure out how to do that. I can only find…
Amir M
  • 508
  • 1
  • 8
  • 28
0
votes
4 answers

Do I need to dispose SPWeb here...?

protected void getNews() { using (SPWeb web = getWeb("InternalNews")) { fetchNewsFromWeb(ref dtNews,true,"English",new string[] { "Internal news page" },web,startDate,endDate,false,true); } } protected…
code master
  • 2,026
  • 5
  • 30
  • 49
0
votes
1 answer

Sharepoint 2010: How to persist SPList objects?

I am writing a replacement for the sharepoint asset picker dialog with additional features. There is a requirement to browse media libs which are located in other site collections. So I added a configuration page where you can add the URLs to the…
elsni
  • 1,953
  • 2
  • 17
  • 35
0
votes
1 answer

Extracting SPWeb.Groups.Xml in XElement

I need to get SPWeb.Groups.Xml in XElement to create XDocument. SPSite site = new SPSite(url); foreach (SPWeb web in site.AllWebs) { SPUserCollection spusers = site.RootWeb.SiteUsers; XElement xeGroup =…
BeHappy
  • 138
  • 2
  • 17
0
votes
1 answer

Why is this considered an "Unsafe Update" in Sharepoint?

I have code like this to conditionally create a Sharepoint list (sort of an upsert): private void ConditionallyCreateList() { SPWeb site = SPContext.Current.Web; // Check to see if list already exists; if so, exit if…
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
0
votes
1 answer

Why does this Sharepoint Files.Add() result in an I/O Error?

With this code: using (var ms = new MemoryStream()) { using (var doc = new Document(PageSize.A4, 25, 25, 10, 10)) { //Create a writer that's bound to our PDF abstraction and our stream using (var…
0
votes
2 answers

SPCrossListQuery fails to bring back results

I am calling SPWeb.GetSiteData(anSpCrossListQuery). It fails to bring back any results or any errors when I call it with an accidental space at the end of the CAML query clause. Anyone have an idea why?
Nat
  • 14,175
  • 5
  • 41
  • 64
0
votes
2 answers

Does the C# `Using` statement close the variable if an error happens inside the using clause

Possible Duplicate: What is the C# Using block and why should I use it? If I ran the following code: using (SPWeb web = SPContext.Current.Site.OpenWeb("/myweb")){ //error happens here } Would the object web be disposed of properly if an…
iambriansreed
  • 21,935
  • 6
  • 63
  • 79
0
votes
2 answers

why my sharepoint workflow always stop when i use this code?

I need to find an user in a list to set the assignedto task property, these informations are in a list. So i use this method : public static SPUser GetSPUser(SPListItem item, string key){ SPFieldUser field = item.Fields[key] as SPFieldUser; …
LoKtO
  • 189
  • 2
  • 9
0
votes
1 answer

Another lists on site (Sharepoint 2010)

This is a question I can't handle, so please, give me some advice. Here is my code for getting names of all lists: private List GetAllLists() { site = SPContext.Current.Site; web = site.OpenWeb(); List
Viaches
  • 143
  • 1
  • 16
-1
votes
1 answer

Is it posible to do app for SharePoint that create another site and create a list and libraries on this other site?

I want to create my first SharePoint App. I am wondering, is it possible to create an app which will create SharePoint site and will build a structure (with a few lists and libraries) on this site?
1 2
3