PowerShell Script – To Export data from XML file to SharePoint list

Export Data from XML file to SharePoint list – using PowerShell script

1.    Open the Script.ps1 file in notepad and edit it.
2.    Change the location of the XML file (Data.Xml) in the #set up connection area.
3.    Change the Site URL in the #set up connection area.
4.    Change the web in the #set up connection area.
5.    Change the list name in the #set up list connections area.
6.    Go to Power shell command prompt and type the command à Path of the script.ps1 file à e.g. C:\script.ps1
7.    The functionality will be achieved.
Also attached here is the list template (.stp) for the required list (ProjectDetails.stp).

You can upload the template on your SharePoint site to create the list and then update the script.ps1 file accordingly so as to achieve the requirement.

*If the list field names are changed, then script.ps1 will be modified accordingly.


How to test Emails delivery on a developer server box, where outgoing emails are blocked

         –         In many business cases, there is every now and then a requirement to send emails to administrator or users of the system.

         At times, the outgoing emails are blocked on the dev boxes / servers, which hamper testing the email module in the    application.
         There is a workaround, to preview the outgoing email at the local dev box along with all the body, subject, recipients etc.

In the Web.config file for the application, place the following entries within the section.

<smtp deliveryMethod=“SpecifiedPickupDirectory”>
<specifiedPickupDirectory pickupDirectoryLocation=“c:\Mails” />
<proxy autoDetect=“true” />

The mail will be stored as a Mail message in the folder specified in the web config file, through which we can verify the contents and detail of the mail.

Create and Assign Custom Permission levels programatically in SharePoint

Sometimes, we come across a business requirement, where in:

We need to create SharePoint sites on the fly (maybe using a site definition), which have their own unique permission and groups.
We might need to create a custom permission level for the contributors for this site, say which does not have the delete rights but all other Contributor rights as is.
Then we need to assign this custom permission level to Contributor group and remove the default ‘Contribute’ permission level from the site.


/// Creating & Assigning custom permission
/// level to Contributor group of root site

/// SpWeb object
/// Group on which the custom permission
/// has to be applied

privatevoid CreateAssignCustomPermissionLevel(SPWeb spWeb, SPGroup myGroup)

spWeb.AllowUnsafeUpdates = true;
//Get the role definition collection for this SPWeb
SPRoleDefinitionCollection sprdcoll = spWeb.RoleDefinitions;
//Define the new custom RoleDefinition
SPRoleDefinition roleDefinition = new SPRoleDefinition();
roleDefinition.Name = “MyCustomRoleDefinition”;
//And then start giving all permisions that you want to give.
roleDefinition.BasePermissions =
| SPBasePermissions.EditListItems
//| SPBasePermissions.DeleteListItems //Delete permission removed from this definition.
| SPBasePermissions.ViewListItems
| SPBasePermissions.OpenItems
| SPBasePermissions.ViewVersions
| SPBasePermissions.DeleteVersions
| SPBasePermissions.CreateAlerts
| SPBasePermissions.ViewFormPages
| SPBasePermissions.BrowseDirectories
| SPBasePermissions.ViewPages
| SPBasePermissions.BrowseUserInfo
| SPBasePermissions.UseRemoteAPIs
| SPBasePermissions.UseClientIntegration
| SPBasePermissions.Open
| SPBasePermissions.EditMyUserInfo;

//Add role definition to spweb

//Assign custom role definition to the contributor group
SPRoleAssignment assignment = new SPRoleAssignment(myGroup);
//Add custom role definition to the SPRoleAssignment
//Add the custom RoleAssignment to the SPWeb.

//Once we have the custom permission level assigned to contributors group,
//we need to remove the default ‘Contribute’ permission level from this web
spWeb.AllowUnsafeUpdates = false;

This method can be placed in feature receiver, where this feature is activated when the site is created on the fly.