10 votes
Accepted

How can I count Document library in Sites(SPWeb) Level?

No need for looping , just get the library at a specific site based on the base type equal to DocumentLibrary then get count of collection as the following : using(SPSite site = new SPSite("https://...
Mohamed El-Qassas MVP's user avatar
6 votes

How can I count Document library in Sites(SPWeb) Level?

You can try this- as bellow using(SPSite oSite = new SPSite("https://server/site")) { using (SPWeb oWeb = oSite.OpenWeb()) { SPListCollection docLibraryColl = oWeb.GetListsOfType(...
Ram's user avatar
  • 2,444
6 votes

How to get the value of list count in SPWeb level?

SPWeb.Lists.Count.ToString(); is correct way to find number of Lists for any SPWeb. You might be seeing in difference in count you see here and in Site is because SharePoint has couple of hidden list ...
Siddharth Vaghasia's user avatar
5 votes
Accepted

Cannot get Webs of SPSite object

All permissions required to correct this error: Site Collection administrator on the SPSite (whether given through Central Admin or Site Settings) PowerShell scripting admin: add-spshelladmin domain\...
Karthik Jaganathan's user avatar
5 votes
Accepted

SP - What is the reason to use "using" in WebParts

First of all, it doesn't have any to do with your code begin run in a web part (or any other specific position). What really matters here is that you are creating a new instance of a SPSite/SPWeb ...
SPArcheon's user avatar
  • 6,868
4 votes

SPWeb.Exists returns true for web don't exists

I think you're running in the OpenWeb() danger when you're not passing in an argument to the method. It is probally opening the RootWeb of your sitecollection which still exists. You need to pass in ...
bartd's user avatar
  • 106
4 votes
Accepted

How to get the value of list count in SPWeb level?

This is because of the SPWeb.Lists.Count.ToString(); return the number of all lists and libraries not only lists To can get the accurate number of lists only you should exclude the library and other ...
Mohamed El-Qassas MVP's user avatar
4 votes
Accepted

Should i use "using" inside event receiver

No, you should not use a using as you're not instantiating the object - you're getting a reference to an existing object. Let the event receiver handle the life cycle of its own objects.
Derek Gusoff's user avatar
  • 8,011
3 votes
Accepted

Why SPWeb.Group provide a method named Add() that always raises exceptions (that we can not use)

The short answer to this question is, Add method is there for Type consistency which makes the life easier for the Developers, both the SharePoint library(dll) developers and general SharePoint ...
AmitWiki's user avatar
  • 1,029
3 votes

How to get the value of list count in SPWeb level?

Try following code using (SPSite site = new SPSite("Web Url")) { using (SPWeb web = site.OpenWeb()) { Console.Write(web.Lists.Count); Console.ReadLine(); } }...
Akshay Belure's user avatar
3 votes

cant find /_layouts/AreaTemplateSettings.aspx

here is a solution for publishSites: Open the publishing site in SharePoint Designer 2013. Click the Site Settings icon on the ribbon. SiteOptions_in_SPD Modify the parameter ...
Imen Turki's user avatar
  • 2,183
3 votes
Accepted

incorrect documentation about the SPItemEventProperties.OpenWeb() method inside visual studio 2012

The SharePoint terminology is vert confusing. Officially, you have the "site collections", and each site collection contains "site"s (the root site and all its sub-sites are sites). There's no "web"...
Evariste's user avatar
  • 9,751
3 votes

Get all groups for a specific web site (NOT SITE COLLECTION) using powershell?

I found the solution. This article helped me out. $web = Get-SPWeb $webUrl; $groups = $web.AssociatedGroups;
ameliapond's user avatar
2 votes

When to dispose SPWeb and SPSite objects

Do I dispose of the web object in this case? No. Do not dispose SPFeatureReceiverProperties.Feature.Parent , For more details check SPFeatureReceiverProperties.Feature.Parent Should I dispose of ...
Mohamed El-Qassas MVP's user avatar
2 votes

SPListTemplateType.DocumentLibrary cannot be used to create a library

If you take a look at the SPListTemplateType construct, it's an enum SPListTemplateType enumeration so when you call SPListTemplateType.DocumentLibrary, what you actually get back is the list type ...
Cthulhubutt's user avatar
2 votes

SP - What is the reason to use "using" in WebParts

The reason for using using is partly correct by the other answers. using is shorthand for try...finally and used on objects implementing IDisposable (more on this in a bit) the dispose part is done ...
Wictor Wilen MCA MCM MVP's user avatar
2 votes
Accepted

Dispose should not be called on this object. // SPDisposeCheck comment

Do not explicitly (or via using) call Dispose() on the SPSite.RootWeb property. The dispose cleanup will be handled automatically by the SharePoint and the .NET framework. For existing SharePoint ...
Jussi Palo's user avatar
  • 8,196
2 votes
Accepted

Determine path to site from a given URL

Try with following JS code <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script> <script> var owebsite; var documentPath = "http://sharepointsite/subsite/Shared%...
Viraj Gorajia's user avatar
2 votes

How can I count Document library in Sites(SPWeb) Level?

Get the document library count using LINQ: SPSite site = new SPSite("siteURL"); SPWeb web = site.OpenWeb(); var totalDocLibrary = (from SPList lst in web.Lists ...
Ronak Patel's user avatar
  • 3,261
2 votes

Why SPWeb.Group provide a method named Add() that always raises exceptions (that we can not use)

Let me first elaborate the difference between SPWeb.Groups and SPWeb.SiteGroups SPWeb.Groups Get a collection that contains all the groups for the subsite. SPWeb.SiteGroups Get a collection that ...
Mohamed El-Qassas MVP's user avatar
2 votes
Accepted

Modifying a list item field using powershell without changing the following values (modifed/modifiedby/Version)

The SystemUpdate() method is indeed what you are looking for. This method will update the item without changing the Modified, Modified By, and Version fields. Your PowerShell script will do exactly ...
Mihail's user avatar
  • 2,099
1 vote

Open web in privileges mode and use it outside

It's not a good practice at all to open an SPWeb in an elevated context with RunWithElevatedPrivileges, close the elevated context and then continue using he SPWeb. A much more simple approach is to ...
Evariste's user avatar
  • 9,751
1 vote

Space in URL causes fail in get-spweb?

You need to put quotes around parameter $SPWeb = Get-SPWeb "http://mysite/web name 1"
Siddharth Vaghasia's user avatar
1 vote

Space in URL causes fail in get-spweb?

It would be $SPWeb = Get-SPWeb "http://mysite/web name 2"
Eric Alexander's user avatar
1 vote
Accepted

How do I differentiate between getchanges REST API call for SPSite and SPWeb?

If you want to query particular object with REST API, you need to use appropriate object in url. For example consider following REST queries: Get changes for site collection: https://sp....
Sergei Sergeev's user avatar
1 vote

How can I count Document library in Sites(SPWeb) Level?

using(SPSite site = new SPSite("https://sitecollectionurl")) { using (SPWeb web = site.OpenWeb()) { int i = 0; foreach (SPList list in web.Lists) { if (list.BaseType == ...
Gautam Sheth's user avatar
  • 30.9k
1 vote

Dispose should not be called on this object. // SPDisposeCheck comment

The code is wrong. You need to use using directive only with objects that you created yourself. The code would be correct in this case: private void AddTaxonomyField(SPSite site) { using (SPWeb ...
Paul Strupeikis's user avatar
1 vote

Import-SPWeb error: "The file xxx.cmp does not exist."

According to the options present in the command line the import may not work. So, add or remove options untill it works: Import-SPWeb https://test.mywebsite.com/another_site/test -Path "export.cmp" ...
ameliapond's user avatar
1 vote

SP - What is the reason to use "using" in WebParts

These Site and Web objects take up lots of memory and needs to be released at the end of the usage. This is also taken care by the CLRs garabage collector. However it would be best practice if you ...
bkk's user avatar
  • 1,307

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