Showing posts with label SharePoint 2010. Show all posts
Showing posts with label SharePoint 2010. Show all posts

Friday, April 6, 2012

Reserved words in SharePoint url

Avoid using these words in any SharePoint url (file name, folder name, site name etc.):

CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9

You can create folder named “CON”, but when you go to folder url, you get 404 error.

Thanks to the following articles:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
http://spcz.blogspot.com/2012/03/sharepoint-reserved-words.html

Friday, January 13, 2012

How to initialize PeopleEditor control?

You can use CommaSeparatedAccounts property for users. But this property doesn’t work for groups.

SPGroup
PeopleEditor peopleEditor = ...;
SPGroup group = ...;
PickerEntity entity = new PickerEntity
{
Key = group.LoginName,
DisplayText = group.Name,
Description = group.Name,
IsResolved = true
};
entity.EntityData.Add("AccountName", group.LoginName);
entity.EntityData.Add("SPGroupID", group.ID.ToString());
entity.EntityData.Add("PrincipalType", "SharePointGroup");
peopleEditor.Add(entity);


SPUser

PeopleEditor peopleEditor = ...;
SPUser user = ...;
PickerEntity entity = new PickerEntity
{
Key = user.LoginName,
DisplayText = user.Name,
Description = user.Name,
IsResolved = true
};
entity.EntityData.Add("AccountName", user.LoginName);
entity.EntityData.Add("SPUserID", user.ID.ToString());
if (user.IsDomainGroup)
entity.EntityData.Add("PrincipalType", "SecurityGroup");
else
entity.EntityData.Add("PrincipalType", "User");
peopleEditor.Add(entity);

Wednesday, January 11, 2012

How to handle version conflict during Update operation

You can use Microsoft.Office.Server.Utilities.EventReceiverUtility class and IsVersionConflictException method. You can find it useful when you use SPWeb.AllProperties for some application counter for example.

SPWeb web = ...;
bool retry = true;
int count = 0;
while (retry)
{
try
{
int lastId = 0
if (web.AllProperties.ContainsKey("LastId"))
lastId = (int)web.GetProperty("LastId");
else
web.AddProperty("LastId", lastId);

lastId++;
web.SetProperty("LastId", lastId);
retry = false;
}
catch (Exception ex)
{
if (!EventReceiverUtility.IsVersionConflictException(ex))
throw;
if (count > 2)
throw;
}
count++;
}