Thursday, 23 December 2010
// Get the SPSite object
SPSite site = new SPSite("URL");
if (site != null)
SPWebApplication webApp = site.WebApplication;
// Create the modification entry
SPWebConfigModification webEntry = new SPWebConfigModification("Web Config entry " ,"Entry location" );
// Add the web config entry to the collection
Web Config Entry could be
Entry location could be
Wednesday, 15 December 2010
Suddenly I started getting "Could not load file or assembly CustomMarshalers" at certain line of my code. It was difficult to understand why same code is not running in new environment. I investigated a bit and found that "CustomMarshalers" is required for compact framework which is not at all useful in my application. Ii couldn't found any solution except changing my code.
1. I had used LINQ queries at few places in my application so i had to change it to CAML query to run in all the environment
2. Wherever I was using "foreach" block and using Sharepoint object collection like SPListItemCollection, I was getting mentioned error. So I had replace all the "foreach" blocks with "for" construct.
I hope these information may help somebody....
backup-spsite -identity "site-collection-path" -path "backup-location"
site-collection-path : http://machinename:port/sites/sitecollectionname
backup-location : D:/backup/site.bak
restore-spsite -identity "site-collection-path" -path "backup-location" -Force
Note: You can not restore more than one site collection in a web application so you have to create a new database. Below command can be used to overcome this issue.
restore-spsite -identity "site-collection-path" -path "backup-location" -Force -DatabaseName "DBNAME"
To Create a new Database follow below instruction
Goto Central Administration---> Manage Content Databases-->Add New Content Database
Monday, 13 September 2010
This view cannot be displayed because the number of lookup and workflow status columns it contains exceeds the threshold (8) enforced by the admin..
This view cannot be displayed because the number of lookup and workflow status columns it contains exceeds the threshold (8) enforced by the administrator
Sharepoint 2010 has default "Resource Throttling" settings. Due to which this warning would be encountered. To overcome this warning, we can increase the number of lookup columns in following ways.
* Goto --> Application Management --> Manage Web Application.
* Select your web application.
* General Settings (on Ribbon window) --> Resource Throttling.
* Resource Throttling window, goto "List View Lookup Threshold" and give the value as per your requirement.
Tuesday, 31 August 2010
Reason for the Delay:
In order to avoid the delay we have to execute our function "onload" event of any control and following steps can be considered to achieve this functionality.
// My method logic
2.Create a "img" element anywhere on your page(Since we can not capture "onload event" of most of the controls).
3. Set the image source to "/_layouts/images/blank.gif" so that nothing is visible on the page.
<IMG SRC="/_layouts/images/blank.gif" width="1" height="18" onload="MyMethod();"/>
Note: Mentioned issue is quite visible in case you are trying to hide/show some buttons/controls of the page on load of the page.
Thursday, 26 August 2010
You can use Client object model from remote computer to access sharepoint site and do CRUD operation.
Below is the sample code to create listitem using Sharepoint client object model.
// Create ClientContext Object
using (ClientContext clientContext = new ClientContext("http://sitename"))
// Give the credential
clientContext.Credentials = new System.Net.NetworkCredential("username", "password", "domainname");
Web site = clientContext.Web;
List list = clientContext.Web.Lists.GetByTitle("ListName");
// To use site object load it first
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem listItem = list.AddItem(itemCreateInfo);
listItem["Title"] = "Created through Client Object Model";
// Execute the query to push data on the server.
Tuesday, 24 August 2010
While creating the SPSite object I was getting following error.
"The Web application at http://sitename/ could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application."
The error was very much misleading, after struggling a bit I found that by default client application's platform target was set to X86 i.e 32 bit so it was not able to access the webapplication which is targeted as 64 bit. So to overcome this issue I had to change my platform target to "AnyCPU" or X64.
Ironically, it was working fine when I was using "Sharepoint Client Object Model"
Saturday, 21 August 2010
Web Parts (code only; not visual Web Parts)
You can not target your solution as sandboxed, in case any of your solution components fall within following SharePoint items:
Visual Web Parts (they contain web controls that have to be deployed to disk)
Business data connectivity models
Call web services in an intranet or over the Internet
Access data outside the site collection where the solution has been deployed
Read and write files with your code
Run code that is not marked to allow partially trusted callers
Use objects above SPSite (e.g., SPFarm)
Use security-related functions (RunWithElevatedPreviledges)
Impersonation of Users
Custom Workflow or programmatically invoking SharePoint Designer workflow
Programmatically accessing Taxonomy data/ Metadata Management
Looking at the above allowed/restricted items, it is quite evident that Sandbox solutions would provide more security and control but lesser features. Whereas farm based solution would not restrict any thing but it would developer’s prerogative to handle the security and avoid malicious code, which would result into more number of code reviews and unit testing
Why Sandbox came into picture
Earlier to Sharepoint 2010, if you are creating a sharepoint application using Sharepoint Object Model, code needs to be thoroughly reviewed and tested before it goes to Production Server to avoid any malicious code. Testing and code review is a big effort which is directly proportional to number of features or LOC of my application. I found Sandbox Solutions to be a real solution to the mentioned problem. Also it provides a good peace of mind to Sharepoint administrator because now they can do better monitoring and resource allocation per Site Collection. Apart from this they can validate the solution before it gets deployed.
After digging more I found that Sandbox Solutions are great but it can’t cater to all kind of Sharepoint applications.Sandboxed solutions run with lower trust level for hosted environments. A sandboxed solution cannot access the full SharePoint object model; it is limited to a subset of the Microsoft.SharePoint namespace. Sandboxed solutions run in a safe and monitored process with restricted access to resources.
Tuesday, 17 August 2010
To impersonate a specific user, you need the usertoken of the impersonated user and you have to pass it while creating the SPSite object.
SPUserToken userToken = Web.SiteAdministrators["loginname"].UserToken;
using(SPSite site = new SPSite("SiteURL", userToken))
SPWeb Web = mySite.RootWeb;
// Perform activities which require administrative privileges
Friday, 4 June 2010
Error occurred in deployment step 'Activate Features': Timeout occurred while running the SharePoint Sandboxed Code service. This service is required to run sandboxed solutions in SharePoint. Please ensure the service is configured correctly in SharePoint
Goto Services and start "Sharepoint 2010 User Code Host" Service
Wednesday, 2 June 2010
In order to call a web service in sandbox environment following steps should be followed.
Note: Assuming you already have created the web service and deployed it in IIS
1. Create a class library project and which is derived from “SPProxyOperation” (Microsoft.SharePoint.UserCode namespace).
Code Snippetclass ProxyProvider : SPProxyOperation
public override object Execute(SPProxyOperationArgs args)
if (args != null)
ProviderSoapClient client = new ProviderSoapClient();
ProviderArgs providerArgs = args as ProviderArgs;
return "Error while calling Web Service...";
2. Create another class which should be used for passing arguments to the SPProxyOperation class
3. Argument class must have “Serializable” attribute. public class ProviderArgs : SPProxyOperationArgs
public int DeptCode
public ProviderArgs(int code)
this.DeptCode = code;
public class ProviderArgs : SPProxyOperationArgs
4. Implement Execute method of SPProxyOperation class.
5. Attach below attribute with the assembly
6. Make sure assembly is strongly named.
7. Deploy the assembly in GAC using GACUTIL(Since drag and drop assembly gives access denied error).
8. Register the assembly in Sharepoint
To register a assembly in Sharepoint “Power Shell” can be used.
Write below scripts in a .ps1 file and run from power shell
$userCodeService = [Microsoft.SharePoint.Administration.SPUserCodeService]::Local
$proxyOperationType = new-object -typename Microsoft.SharePoint.UserCode.SPProxyOperationType -argumentlist $assemblyName, $typeName
9. Since this is full trust proxy class so it would run under “SPUCWorkerProcessProxy.exe” so add the web service related configuration setting in SPUCWorkerProcessProxy.exe.config file which can be found under “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\UserCode” folder.
10. Now you are ready to call the web service method via Proxy operation class. Use below method to call the web service from your Sandbox Solution.
SPUtility.ExecuteRegisteredProxyOperation("AssemblyName, Version=184.108.40.206, Culture=neutral, PublicKeyToken=fffdd72d4537ce50", "NameSpace.ClassName", new ArgumentClass(Argument));
To query SharePoint List or Document Library in specific Folder “ FolderServerRelativeUrl ” as part of the CAML Query Code Snippet ...
Recently, I stumbled upon a situation where I had Calendar list and I had provided custom save and cancel button. In List setting I had kep...
In order to call a web service in sandbox environment following steps should be followed. Note: Assuming you already have c...