Questions tagged [spsite]

Represents a collection of sites in a Web application, including a top-level Web site and all its subsites.

Definition:

Represents a collection of sites in a Web application, including a top-level Web site and all its subsites. Each SPSite object, or site collection, is represented within an SPSiteCollection object that consists of the collection of all site collections in the Web application.

More reading:

Code example:

//providing an absolute URL, 
SPSite mySiteCollection = new SPSite("http://mysharepointsite/");

//using the current context
SPSite mySiteCollection = SPContext.Current.Site;

SPSite 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 with the Context. So in the second line, the Dispose() should not be called. You can close it manually or use the using statement to do this for you:

//manually
mySiteCollection.Dispose();

//using statement
using (SPSite mySiteCollection = new SPSite("http://mysharepointsite/")
{
    //your code here
}
37 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
6
votes
3 answers

SPSite.Exists(url) return false although the url exists

Does anybody know why SPSite.Exists(url) return false although the url exists. If I check the above statement, it returns false. But I can open the site without any problems if I directly use SPSite myRootSite = new SPSite(url); Here is my coding…
kevin
  • 13,559
  • 30
  • 79
  • 104
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
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
4
votes
2 answers

copy site collection in Sharepoint 2010

I would like to be able to copy the entire site collection http://server.ltd/sites/ABC to http://server.ltd/sites/DEF is there any easy solution, because I tried to Save as template at the site level then tried to upload the solution to the newly…
Rabie K
  • 43
  • 2
  • 6
4
votes
3 answers

SharePoint SPSite Disposing

The scenario I have, is in the Execute method of a SPJobDefinition I want to go through every SPSite in the web application. So I have the following code: foreach (SPSite site in this.WebApplication.Sites) { ... } Question is, do I need to…
Daniel Revell
  • 8,338
  • 14
  • 57
  • 95
3
votes
4 answers

Sharepoint SPSite

I am trying to create a spsite of object for sharepoint search but i am getting exception in production as website not found SPSite site = new SPSite("sitename"); ServerContext scon = ServerContext.GetContext(site); SearchContext srchcontext =…
kailash
  • 51
  • 1
  • 3
3
votes
1 answer

How to detect events when user goes from one site collection to another in the same web application?

I have a several site collections in the same web application and I need to handle events when user goes from one site collection to another. I need it for specific actions, like setting "lcid" cookie for changing default language of site and claims…
Oleg Savelyev
  • 968
  • 2
  • 8
  • 12
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
4 answers

How to get all site collections in a web application

I want to list all site collections under my web application; the purpose is to list all mysites created by users. Like that: /members/sites/sqladmin /members/sites/sqluser /members/sites/sqluser1 /members/sites/sqluser2 /members/sites/user1
markov00
  • 100
  • 1
  • 1
  • 9
3
votes
2 answers

Why can I get SPSite in PowerShell but fails with FileNotFound in c#?

We have a mixed (forms and Windows)-based SharePoint 2010 site and I'm attempting to use the object model in c# (command line console app, referenced to Microsoft.SharePoint, Solution Platform target is x64 [in VS 2012 I had to create a new solution…
Michael
  • 1,786
  • 5
  • 23
  • 42
2
votes
3 answers

Issus deleting a site collection

I'm currently doing some test where I try to delete a site collection programmatically. Thereby I realized some strange behavior by SharePoint. I used the following code to test the site collection deletion. private static void…
Flo
  • 27,355
  • 15
  • 87
  • 125
2
votes
3 answers

Sharepoint in MVC

I have been trying to get my MVC C# code to connect to my sharepoint server. I have tried everything and I keep getting this error no matter what I try. The Web application at [http://myserver/] could not be found. Verify that you have typed the…
1
vote
2 answers

How do I specify the encoding of an SPSS syntax file?

I am writing out statistical results in SPSS with code like OMS / SELECT Tables Headings / DESTINATION FORMAT = OXML OUTFILE='C:\Temp\outfile.xml'. The syntax file is saved as UTF-8 (with bookmark). It has some words with umlauts (german…
Daren Thomas
  • 67,947
  • 40
  • 154
  • 200
1
vote
2 answers

How to identify the SharePoint exception when trying to create a new site

Ok, This seems stupid but I figured I would ask because there is a lot of expertise to tap into here and I will probably learn a good bit from the answers. I have a service center panel for creating sites. If site creation fails, I would like to…
Anthony Graglia
  • 5,355
  • 5
  • 46
  • 75
1
2 3