Archive

Posts Tagged ‘visual studio’

Creating Custom Profile Property in SharePoint Server 2010

March 31, 2013 Leave a comment

if you have requirements to create Custom Profile Property in SharePoint 2010

below function do That

private
void CreateCustomProperty(string profilePropertyText,SPSite siteColl)

{


SPSecurity.RunWithElevatedPrivileges(delegate()

{

siteColl.AllowUnsafeUpdates = true;

siteColl.OpenWeb().AllowUnsafeUpdates = true;


//SPContext.Current.Web.AllowUnsafeUpdates = true;


SPServiceContext serviceContext = SPServiceContext.GetContext(siteColl);


UserProfileConfigManager profileConfigManager = new
UserProfileConfigManager(serviceContext);


CorePropertyManager coreProperties = profileConfigManager.ProfilePropertyManager.GetCoreProperties();


try

{


List<string> MyCustomProperties = new
List<string>();

MyCustomProperties.Add(profilePropertyText);


ProfilePropertyManager propertyManager = profileConfigManager.ProfilePropertyManager;


foreach (string profileProperty in MyCustomProperties)

{


if (coreProperties.GetPropertyByName(profileProperty) == null)

{


CoreProperty propertyInstance = coreProperties.Create(false);

propertyInstance.Name = profileProperty.Replace(” “, string.Empty);

propertyInstance.Type = PropertyDataType.String;

propertyInstance.Length = 2000;


//propertyInstance.Separator = MultiValueSeparator.Semicolon;

propertyInstance.DisplayName = profileProperty;

propertyInstance.Description = profileProperty;

propertyInstance.IsAlias = false;

propertyInstance.IsSearchable = true;

propertyInstance.Commit();


ProfileTypePropertyManager profileTypePropertyMgr = propertyManager.GetProfileTypeProperties(ProfileType.User);


ProfileTypeProperty profileTypeProperty = profileTypePropertyMgr.Create(propertyInstance);

profileTypeProperty.IsVisibleOnViewer = true;

profileTypeProperty.IsVisibleOnEditor = true;

profileTypePropertyMgr.Add(profileTypeProperty);


ProfileSubtypeManager psm = ProfileSubtypeManager.Get(serviceContext);


ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));


ProfileSubtypePropertyManager pspm = ps.Properties;


ProfileSubtypeProperty psp = pspm.Create(profileTypeProperty);

psp.IsUserEditable = true;


//psp.Commit();

pspm.Add(psp);

}

}

siteColl.AllowUnsafeUpdates = false;


//SPContext.Current.Web.AllowUnsafeUpdates = false;

siteColl.OpenWeb().AllowUnsafeUpdates = true;

}


catch (DuplicateEntryException exception)

{

siteColl.AllowUnsafeUpdates = false;


SPContext.Current.Web.AllowUnsafeUpdates = false;

logMessage(exception.Message, EventLogEntryType.Error);

}

});

}

to check if specific Profile Property exist or not

private
bool CheckCustomPropertyExistance(string profileProperty, SPSite siteColl)

{


bool exist = false;


SPSecurity.RunWithElevatedPrivileges(delegate()

{


SPServiceContext serviceContext = SPServiceContext.GetContext(siteColl);


UserProfileConfigManager profileConfigManager = new
UserProfileConfigManager(serviceContext);


CorePropertyManager coreProperties = profileConfigManager.ProfilePropertyManager.GetCoreProperties();


try

{


if (coreProperties.GetPropertyByName(profileProperty) != null)

{

exist = true;

}

}


catch (DuplicateEntryException exception)

{

logMessage(exception.Message, EventLogEntryType.Error);

}

});


return exist;

}

Advertisements

Importing SharePoint Solution Package (WSP) into Visual Studio 2010

December 30, 2012 1 comment

In this article I’m talking about importing WSP as a result of exporting site template into visual studio 2010.

Let us go to our demo steps

1-      Go to site setting -> Save site as template

 

2-Give exported template a name and description, and check Include Content checkbox in case you want to export all site contents

3- Go to site setting,  You will get a link to your “solution gallery”, which has your template.

4-Open visual studio 2010 -> Create New Project  ->Import SharePoint Solution Package

5- Select “Deploy as Farm “ option

6-Select the path of existing solution


7-    After importing this WSP, a wizard will appear with all contents of WSP and give developers to select and deselects items.

8-Visual studio Solution