API for interacting with SharePoint from .NET code deployed to the server.
22
votes
2answers
3k 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.
16
votes
3answers
913 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 ...
10
votes
3answers
3k 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
2k 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
5k 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
2answers
173 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
521 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
2k 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
358 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 ...
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
357 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
368 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
221 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
3answers
911 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
3k 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
1answer
154 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
452 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
1k 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
2k 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.
...
3
votes
1answer
346 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
2k 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
3answers
4k 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
515 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
3answers
721 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 ...
2
votes
1answer
238 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
1answer
710 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 ...
2
votes
2answers
1k 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 ...
2
votes
1answer
123 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
2answers
598 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
2k 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 ...
2
votes
3answers
801 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
1answer
644 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
241 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
2k 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
127 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
3answers
12k 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.
2
votes
4answers
268 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 ...
2
votes
4answers
5k views
Make a copy of sharepoint site under a new name
Since we can't save SharePoint site (with publishing feature enabled) as Template, I'm looking for a way to do this programmatically :
Make a copy of "SiteA" with a new name
"SiteB" under the ...
2
votes
2answers
153 views
Sharepoint Web Part restrict to zone
Is there any way to restrict a web part to a certain zone? I know I can restrict it by using the AllowZoneChange flag, but is it possible to make sure the web part can only be added to certain zones? ...
2
votes
1answer
74 views
Possible to use the object model to push content across two different web applications?
I've been able to use the object model to move list items between sites in the same site collection, but I'm wondering if I can use it to move list items between two different web applications on ...
2
votes
2answers
355 views
How to enable custom ordering on a list?
I want to be able to create a list programmatically which allows end users to reorder the items in the list. There appear to be 2 steps to this. Firstly set the SPList.Ordered property to true - this ...
2
votes
1answer
634 views
How is a link to a Meeting Workspace stored for a Calendar Event?
If you open the DispForm.aspx for an item in a Calendar List, you see a link and display text to the Meeting Workspace (if one exists) for that event.
How can I access the link to the Meeting ...
2
votes
1answer
52 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 ...
2
votes
1answer
134 views
Server side equivalent of this Client Object Model code?
I have the following javascript:
SP.ListOperation.Selection.getSelectedItems();
And I'm wondering if there is a Server Side Object Model equivalent to this that I could use in Page Load?
The ...
2
votes
3answers
188 views
Deny user access from SharePoint Native but allow it from custom application
How can i restrict a user from entering SharePoint - unless he is using my custom application?
For example, a user tries to open http://Mysite , he gets an access denied error.
But as the same time, ...
2
votes
1answer
595 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 ...
2
votes
1answer
243 views
Setting the value of a custom web part property using object model
Let's say I have a reference to a web part that I got by using a SPLimitiedWebPartManager. How can I set the custom properties of that web part? For example, if it is a stock ticker web part, how do I ...
2
votes
3answers
964 views
WCF Service @ SharePoint 2010 TimeOut
I have been developing on SP 2010 for a while now. Mostly I have been working with the Client Object Model.
Though I am at a point where I need to read out the UserProfiles from inside SharePoint.
...
2
votes
1answer
70 views
Deleting a SharePoint User Profile remotely
Can anyone tell me how to delete a SharePoint user profile remotely? I don't see a way to do this using SharePoint Web Services or User Profile Services. The following code works fine when run on ...
2
votes
1answer
505 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...?

