Pages

Tuesday, February 9, 2016

"Error while enabling Windows feature: NetFx3" while installing sql server 2012 on windows server 2012.

You may have experienced  the above error while setting up sql server 2012 on windows server 2012. Reason for raising this error is .Net Framework 3.5 feature is required by SQL Server 2012.









This post is going to describe for you that how to solve this problem by simply using Windows PowerShell.

1.Insert Windows server 2012 installation disk to the CD/DVD Drive or keep a copy of installation media somewhere in your Local Hard Disk.
2.Open Windows PowerShell under administrator privileges. (Run as admnistrator)
3.Type following command as mentioned below with necessary replacements.

Install-WindowsFeature Net-Framework-Core -source [path_to_the_file - ...\sources\sxs]

ex: Install-WindowsFeature Net-Framework-Core -source F:\sources\sxs] - Using installation media in CD/DVD Drive.
Install-WindowsFeature Net-Framework-Core -source D:\Windows_Server_2012_R2\sources\sxs] -Using installation  media in Local Disk.

Now retry installing SQL Server 2012 with same steps you followed early.

Wednesday, January 27, 2016

"Invalid text value. A text field contains invalid data. Please check the value and try again." Error at SPListItem.Update() in SharePoint

When developing sharepoint solutions you may have experienced this common issue while inserting or updating items in sharepoint lists programmatically.

This exceptions occurs when trying to insert or update a column in "Single line of text" type with a value which contains more than 255 characters.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Runtime.InteropServices.COMException: 

Invalid text value

A text field contains invalid data. Please check the value and try again.

Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace
at Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish)
   at Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, Boolean bSystem, Boolean bPreserveItemVersion, Boolean bNoVersion, Boolean bMigration, Boolean bPublish, Boolean bCheckOut, Boolean bCheckin, Guid newGuidOnAdd, Int32& ulID, Object& objAttachmentNames, Object& objAttachmentContents, Boolean suppressAfterEvents)
   at Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents)
   at Microsoft.SharePoint.SPListItem.Update()


To fix this error, you have to limit the value which you are trying to update in "Single line of text" column to 255 characters or change the type of column to "Multi lines of text". 

Note: "Multi lines of text" field has defined in sharepoint as a 'Note' type and this is stored in the the DB as a ntext sql type.In the SQL type can store 2GB of char data, that's 1,073,741,823 characters.

Sunday, January 24, 2016

Get Root Site URL from a Sub Site Programmatically

You can access the URL of the root site of your sub site using Uri property.

private string GetRootSiteUrl()
{
   string urlValue = "";
   using (SPSite sPSite = new SPSite(site.ID))
   {
      using (SPWeb sPWeb = sPSite.OpenWeb(web.ID))
      {
         Uri url = new Uri(sPWeb.Url);
         urlValue = url.GetLeftPart(UriPartial.Authority);

         return urlValue;
      }
   }
}

Migrate Users Across Site Collections in SharePoint Programatically

When you are working with SharePoint site collections you have experienced with managing contents in site collections from another site collection. (access root site contents from a sub site within the same web application). In this case when you need to copy user values from one site to another, then you need to ensure the user between two sites.

Using "EnsureUser"method:
SPUser currentWebUser = SPContext.Current.Web.EnsureUser(User.LoginName);

The EnsureUser method returns a valid SPUser object which can be use within site..

Ex: Add to a UserGroup:
SPGroup group = web.Groups[GroupName];
group.AddUser(currentWebUser);

Monday, January 18, 2016

Manage Permissions on List Views for Different Users / Groups in SharePoint 2013

Follow these steps: -
  • Open the list with all items view (ex. Lists/EmployeeMaster/Allitems.aspx). 
  • Go to Site Actions and select Edit Page 
 Now the web part Allitems.aspx will change to the edit mode.
  • Go to the Web Part section and click Web Part Properties.
 Now the web part properties window will displayed in the right side of the web part.
  • In the List Views pane select the view from the dropdown which you need to manage the permissions.
  • In the Advanced pane select the users/ groups under Target Audiences
  • Click OK.
Follow the above steps to manage access levels and grant permission to user/ groups for different list views.

Sunday, January 17, 2016

Manage permissions for a list, library, or single item or document


This post is going to describe that how to assign unique permissions for a list, library or single list item, or document.

List / Library

Remove inherited permission from Users/Group in list
1. Open the list/library that you want to edit permission
2. Go to List Settings (or Library Settings if it is and library)
3. Go to Permission for this List (or Permission for this Library) under Permission and Management Section.
Permission page for the list will be displayed and you can see that list has inherited permission from site.
4. Click Stop inheriting permissions.
Now the list will be removed inherited permission and it has copy of its own permission.

Remove permission from Users/Group in list
1. Click check box in the left side of user/group name in the name section.
2. Click Remove User Permission under Permissions tab.
 
Grant permission to Users/Groups for list
1. Click Grant Permissions under Permissions tab and then the list permission pop window will displayed.
2. Type names of the users / groups which you need to grant permissions to the list.
3. Click SELECT OPTIONS to edit permission levels for selected users/ groups.
4. Click Share.

Inherit Permissions from Parent
1. Open the list/library that you want to edit permission
2. Go to List Settings ( or Library Settings if it is and library)
3. Go to Permission for this List (or Permission for this Library) under Permission and Management Section
Permission page for the list will be displayed and you can see that list has inherited permission from site.
4. Click Delete unique permissions.
Now the list will be removed inherited permission and it has copy of its own permission.

Note:- Managing permission on single list item or library document will follow the same steps above.

Friday, January 15, 2016

Get values from Person or Group field programmatically


We are using different types of fields when working with SharePoint applications.
One of an important type among them is Person or Group field which is manage user values in site contents. This post has described that how to work with Person or Group field programmatically.

1. Get SPUser from Person or Group field in the list – (When multiple choice and groups are not allowed in the field):
//Get SPUser
SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users");
SPFieldUserValue userFieldValue = (SPFieldUserValue)userField.GetFieldValue(item["Users"].ToString());

SPUser user = userFieldValue.User;

2. Get SPUser when multiple choice is allowed and groups are not allowed:
//Multiple choices are allowed
SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users");
SPFieldUserValueCollection userFieldValueCollection = (SPFieldUserValueCollection)userField.GetFieldValue(item["Users"].ToString());
foreach (SPFieldUserValue userFieldValue in userFieldValueCollection)
{
    Console.WriteLine("     " + userFieldValue.User.LoginName);
}

3. Get SPUser when group is allowed:
//Group or User are allowed
SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users");
SPFieldUserValue userFieldValue = (SPFieldUserValue)userField.GetFieldValue(item["Users"].ToString());

//Tries to get SPUser
if (userFieldValue.User != null)
{
   SPUser user = userFieldValue.User;
}

//if the field contain group
else
{
  SPGroup group = web.SiteGroups.GetByID(userFieldValue.LookupId);
}