posts - 16 , comments - 4 , trackbacks - 0

Tuesday, July 21, 2015

Creating a Folder in a SharePoint List and adding Items to it programatically

Creating a Folder in a SharePoint List and adding Items to it programatically

The following code is to create a folder in a SharePoint list and add items to it. This code is written for a Custom Visual Studio Workflow, the workflow will be started when a new item is added to a list.

public Guid workflowId = default(System.Guid);
public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
SPList list = null;
SPListItem folderItem = null;

private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
{
 SPListCollection listCollection = workflowProperties.Web.Lists;

//Creating folder in "MyContacts" Lists
list = listCollection["MyContacts"];

// create a folder under the path specified
folderItem = list.Items.Add(list.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder);

// set the folder name and update
folderItem["Title"] = "My Folder"
folderItem.Update();

//create a listitem object to add item in the foler
SPListItem listItem = list.Items.Add(folderItem.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, null);

//Set the values for other fields in the list
listItem["Contact ID"] = workflowProperties.Item["Contact ID"];
listItem["Contact Name"] = workflowProperties.Item["Contact ID"];
listItem.Update();
workflowProperties.Item.Update();
oWeb.AllowUnsafeUpdates = false;
}

Posted On Tuesday, July 21, 2015 11:41 AM | Comments (0) | Filed Under [ Creating a Folder in a SharePoint List and adding Items to it programatically ]

Allow users to edit values for this property to IsUserEditable =TRUE at the user profile properties UPN user principal Name(Edit Settings)

if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PsSnapin Microsoft.SharePoint.PowerShell
}
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[System.Reflection.Assembly]::LoadWithPartialName("microsoft.sharepoint.portal")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[System.Reflection.Assembly]::LoadWithPartialName("System.Web")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Taxonomy.dll")
$site = Get-SPSite -Identity $siteurl -ErrorAction Stop
$ctx = [Microsoft.Office.Server.ServerContext]::GetContext($site)
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ctx)
$upcm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($ctx)
foreach($property in $upm.Properties)
{
if($property.Name -eq "SPS-UserPrincipalName")
{
Write-Host $property.IsUserEditable
$property.IsUserEditable = $true;
$property.IsVisibleOnEditor = $false;
$property.IsVisibleOnViewer = $false;
$property.Commit();
}
}

Posted On Tuesday, July 21, 2015 8:27 AM | Comments (0) | Filed Under [ PROPERTY user principal name UPN Allow users to edit values for this property ]

Allow users to edit values for this property to IsUserEditable =TRUE at the user profile properties UPN user principal Name(Edit Settings)

if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PsSnapin Microsoft.SharePoint.PowerShell
}
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[System.Reflection.Assembly]::LoadWithPartialName("microsoft.sharepoint.portal")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[System.Reflection.Assembly]::LoadWithPartialName("System.Web")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Taxonomy.dll")
$site = Get-SPSite -Identity $siteurl -ErrorAction Stop
$ctx = [Microsoft.Office.Server.ServerContext]::GetContext($site)
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ctx)
$upcm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($ctx)
foreach($property in $upm.Properties)
{
if($property.Name -eq "SPS-UserPrincipalName")
{
Write-Host $property.IsUserEditable
$property.IsUserEditable = $true;
$property.IsVisibleOnEditor = $false;
$property.IsVisibleOnViewer = $false;
$property.Commit();
}
}

Posted On Tuesday, July 21, 2015 8:27 AM | Comments (0) | Filed Under [ PROPERTY user principal name UPN Allow users to edit values for this property ]

Powered by: