API for interacting with SharePoint from .NET code deployed to the server.

learn more… | top users | synonyms

25
votes
2answers
5k views

When to use OpenWeb() vs RootWeb

I am a little confused on the pro's and con's of each. When is it good to use OpenWeb() vs RootWeb, especially in the context of a using statement.
18
votes
3answers
1k views

Feature based XML vs. Object Model: Which is better for content type development?

I've been researching a few different ways to create content types and I recently discovered that you can use the Object Model to do this. All of the examples I have found online typically use XML ...
11
votes
4answers
5k views

How to automate entry of external column data in BCS?

I have a document library, Resumes, that has a large number of resumes in it. There is a regular column on that library, called EmployeeID, that is already populated. I have an external content type ...
7
votes
3answers
3k views

Is there a way to see if an SPField was created by a user?

I have some code where I am going through all of the Fields that belong to a content type. I'm curious if there is a way to check to see if the SPField was created by a user or if it is a system ...
6
votes
5answers
8k views

In which situation use SPSecurity.RunWithElevatedPrivileges with superusertoken?

i have given permission only read only to Users Group.so there are not access to see listitem or any list. i have create application page with SPGridview with bind listitem. this page access by this ...
6
votes
3answers
19k views

Sharepoint 2010 how to get all items in a folder contained in a list?

I have a list that contains folders. Using c# and object model, how can I see if the folder contains any items, or return a collection of all the items in that folder.
6
votes
2answers
194 views

Choosing between API and web services

We are designing a system where we will have a service facade, behind this facade will be functionality to update SharePoint. For example to move an item from one list to another. What we are ...
5
votes
6answers
702 views

SharePoint 2007 : How to sign out user?

I've an application build on SharePoint 2007 platform, the problem is in Mozilla FireFox, the sign out button does not successfully sign out the current login user, I believe SharePoint 2007 is not ...
5
votes
1answer
3k views

Fastest way for looping through a SPWebCollection

I've developed a console application for looping through all the webs inside my SharePoint 2010 site, but it's kind of slow, until the point that it throws OutOfMemory exception. This is the code I ...
5
votes
1answer
136 views

How to programatically determine if 2013 running in '14 compatibility mode' (SP 2010)

How can you programmatically determine if a site collection is running in '14 compatibility mode' (so it looks like SharePoint 2010)?
5
votes
1answer
414 views

Custom Web Service not cannot find User

I have created a Custom Web Service for my .NET application that performs various functions against a Sharepoint 2010 site. I use a standard function to run each function as an impersonated user (so ...
5
votes
2answers
103 views

SharePoint App VS Object Model

For designing solutions I am confused with whole Apps concept in 2013. What is Microsoft's guidance for when to use a SharePoint app and when to go for a traditional client or server object model ...
4
votes
3answers
1k views

Should I dispose SPWeb or SPList?

I am doing a whole bunch of things with one SPWeb and many SPLists. If I just dispose web in the finally section would that dispose all of SPLists that I instantiated? (btw, I understand the concept ...
4
votes
2answers
396 views

Performance of search vs. using the object model?

Does anyone know how the performance of searching for items compares to using the object model to access them? When I say "object model" i mean using SPList to get a collection of SPListItems and ...
4
votes
2answers
921 views

Is it possible to have a single document referenced by two different document libraries?

Business Requirements: My customer wants to be able to associate one document with multiple projects. E.g., a set of specifications for a piece of equipment that will be used in multiple projects. ...
4
votes
2answers
3k views

Iterate through discussion list

I have SharePoint 2007 discussion list. I want to iterate over all items in the list, so I do the following: var list = web.Lists["discussion"]; var listItems = list.Items; foreach (var listItem in ...
4
votes
1answer
3k views

Checking existence before using GetItemById

I am getting an item by using GetItemById but I want to check before using it whether the item exists or not. I don't want to use a query as the main purpose of using GetItemById is performance. ...
4
votes
2answers
286 views

Efficiently determine if a List is using item level security

How can you efficiently determine if any of the items in a List don't inherit their security from the List? You could use SPListItem.HasUniqueRoleAssignments but this would require iterating through ...
4
votes
1answer
1k views

How do I remove all users from an SPGroup object?

I have an SPGroup object populated, how can I remove all members from the group, so that essentially I start with a fresh group. I can't delete and recreate it, so I need a way to work with the ...
4
votes
3answers
1k views

How can I modify a file stored in SharePoint via PowerShell?

I have some files in SP 2010 that are simply HTML, and I need to modify the contents of those files in a systematic manner. Is there a good way to do this using powershell? Imagine that I want to ...
4
votes
1answer
4k views

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

this code thow an exception at "Item.Update();" private void AddEmail() { site = SPContext.Current.Site; web = site.RootWeb; ...
4
votes
3answers
510 views

How to programmatically modify item level permissions prior to first save?

I've got a situation where there are strict permissions requirements on an a list of which I already have written a custom form. The requirement is that upon creation, based on metadata, only certain ...
4
votes
1answer
321 views

how to programetically get the type (TemplateType) of a Library using the item url

Imagine if you have image url which is existing within a site collection in Sitecollectionimages library: testserver/Sitecollectionimages/image.jpg How can I get the TemplateType (which kind of ...
4
votes
3answers
666 views

What options are available to me to find lists that were created using a specific list definition?

I have many lists, some of which were created using a custom and now-obsolete list definition. I need a programmatic way of finding out which lists were created using that old definition. Currently ...
4
votes
1answer
2k views

How to find the Author Name using SP Client Context in SharePoint 2010?

I am trying to find the Author Name(created by) for a given Item Id using the SP Client context in SharePoint 2010. Below the code snippet var ctx = new SP.ClientContext.get_current(); ...
3
votes
1answer
5k views

How to update a deployed content-type?

I created a content-type and applied it inside a document library. Now, if I go to the conent-type gallery and delete one of the fields, and then go back to the library and view the available ...
3
votes
1answer
434 views

Possible to get all SiteCollections in a WebApplication from SPContext.Current?

I would like to look at all Site Collections that are in the current web application based on SPContext.Current. Is there a way to do this? If not, how can I achieve this?
3
votes
1answer
3k views

How do I query a list using CAML and SPQuery?

I have a SPList but I don't need to go through everything in that list. I need to establish a CAML query so I can limit the list items. Then, go thru each item from the query result and do something. ...
3
votes
2answers
68 views

Getting spuser from multiple types of information

If this sounds confusing it's because I'm al little confused on it myself. Basically I have an application (originally written by someone else but never finished) that needs to perform various actions ...
3
votes
3answers
6k views

Sharepoint 2010: Custom “New Item” form - showing ribbon and binding events to ribbon buttons

We've created a custom New Item page for our list on our site in Sharepoint 2010 with this code: <asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server"> <table ...
3
votes
1answer
638 views

SPLongOperation never ends

I have an SPLongOperation that occasionally fails to redirect the user to a new page when the operation completes. I'm not sure what circumstances cause the problem, since I don't yet have a reliable ...
3
votes
1answer
146 views

Needed help to build caml Query with multiple <And>

I am getting a query from list view by view.Query i got the following <QUERY> <GroupBy Collapse="TRUE" GroupLimit="100"><FieldRef Name="AlertGrp" /></GroupBy> ...
3
votes
1answer
79 views

How do i “Refresh” each site collection's permissions?

My network admin have deactivated a lot of users from the Active Directory, and recreated them using the same username but with a different OU, Now the SP 2010 does not recognize these users or their ...
3
votes
3answers
940 views

How to create InfoPath forms dynamically?

I have an InfoPath form published to a library... I need to create forms dynamically with siteuser as form name... I need to achieve it in Object Model... Can any of you help me on this...?
3
votes
3answers
849 views

Problem with SPList.SaveAsTemplate

I have never really had too much cause to use this method before but I am developing some generic classes to deal with column, content type and list management for use in a series of features. My ...
3
votes
1answer
801 views

Creating Managed Metadata Field from XML definition

I have successfully recreated all other Column types in SharePoint using the SPFieldCollection.AddFieldAsXml(string xml) method. However, the same method fails for the TaxonomyFieldTypeMulti field ...
3
votes
2answers
1k views

How can I implement SharePoint JSGrid filtering and grouping functionality?

I am working on SharePoint JSGrid. I am able to implement the sort functionality in JSGrid. Now I want to implement the grouping and filtering in my custom JSGrid. For filtering we have to attached ...
2
votes
1answer
285 views

Why do I sometimes have to use different SPQuery tags?

Every SPQuery's query should have <View><Query> query... </Query></View> tags? Sometimes I have to put without those tags to get it work and some times I have to put it ...
2
votes
3answers
79 views

To Dispose or Not to Dispose - IDisposable Passed as Function Parameter

If an IDisposable SharePoint object is passed into a function, does an explicit Dispose() call need to be made on it? Example: public void TheCallingFunction() { SPSite site = ...
2
votes
1answer
246 views

Programmatically get the central administration site SPWeb using server object model

Like in the title - is there a method of getting it without supplying the URL?
2
votes
3answers
353 views

Get absolute URL to listitem's default display form

I need to have an absolute URL of a listitem's display form - currently I do it the following way: On http://mydomain.com/: item.ParentList.ParentWeb.Url.TrimEnd('/') //"http://mydomain.com" + "/" ...
2
votes
1answer
259 views

Is there a way to only clear a specific item from the recycle bin?

I know I can empty the recycle bin for a site collection with the following: public static bool EmptyRecycleBin(string siteCollection) { try { using ...
2
votes
3answers
1k views

Programatically searching the current site collection only

I'm trying to programatically search a sharepoint site. The problem is, the results returned are from all site collections. How can I limit my search to only one site collection. Here is how my code ...
2
votes
2answers
633 views

How do I query several lists with the Object Model and merge the results?

Is it possible to with the Object Model query several lists at the same time and get the result merged together? Something like linked sources in SharePoint Designer? I have created a web part that ...
2
votes
1answer
279 views

SPDocumentLibrary.CheckedOutFiles does not return all files

I am working through some code samples on MSDN that is suppose to return Checked Out files but my tests is showing a problem. Here you can see that both "default" and "foo" in my Page library are ...
2
votes
1answer
908 views

Sending an email using sharepoint object model sharepoint 2010

i have been working on generating email in an event receiver using share point object model..i used the sputility.sendemail method..2 things are necessary in the email(email from and HTML body)..so i ...
2
votes
1answer
253 views

SharePoint object model

I'm looking for articles on custom model mapping for Sharepoint (2007 / 2010). Google's not returning a lot of hits on this, are the any articles out there? Best practices, mapping and such? I'm ...
2
votes
2answers
3k views

How to read items in a BCS external list with PowerShell?

Is there a way that you get information from an external list (created from SPD for a specific ECT) differently than you do from a "normal" SharePoint list when using PowerShell? I did the following: ...
2
votes
3answers
131 views

4 using statements looks messy? Any suggestions on what is a better way to code this?

Imagine the following code: using (SPSite spSite = new SPSite(this.SiteURL)) { using (SPWeb spWeb = spSite.OpenWeb()) { using (SPSite spSite2 = new SPSite(this.SiteURL2)) { ...
2
votes
4answers
297 views

Document Library throws NullReferceException everytime I try to grab an item

This code is from a sequential workflow. I am trying to grab the most recent item in a document library. I check to make sure there are more than zero items in the library, then I try to grab the most ...