Sharepoint Blog - Comments Option  
Author Message
thekaran





PostPosted: SharePoint - Development and Programming, Sharepoint Blog - Comments Option Top

Experts,

We are planning for a sharepoint Blog for our division head.

Our requirements are
1. Blog application must remain secured meaning every user must login to see the blog.
2. User can leave a comment on any post, but he/she gets an option of remaining anonymous on comments.

I know it is it easy to be completely anonymous or completely otherwise, but being both seems not an option for an out of the box MOSS functionality.

I appreciate any thoughts of yours on this.

Thanks,
thekaran


SharePoint Products and Technologies4  
 
 
SharePointing





PostPosted: SharePoint - Development and Programming, Sharepoint Blog - Comments Option Top

Out of the box you are out of luck, You could accomplish this with a custom web part. How savy at Visual Studio are ya

 
 
thekaran





PostPosted: SharePoint - Development and Programming, Sharepoint Blog - Comments Option Top

Not too Savy at VS, me an avid RAD user :)

At last i was able to get things ready for my custom web part development.

I created a boolean column called "Anonymous" in my comments list. This automatically places a check box option on the comments post form (webpart).

i guess, i need to add a small logic something similar to this.. somewhere

if(comment["Anonymous"] == true)

{

comment["Author"] = "Anonymous";

}

Is there a way i can modify the existing New comment webpart on the post.aspx page or Do i need to completely replace the New comment webpart with my custom webpart

Spent some time trying to achieve this using Sharepoint designer. i had some initial luck, tweaking post.aspx page with CAML scripts. Unfortunately, gave up when author information showed up in other places such as search results pages.

I greatly appreciate your help.

Thanks,
thekaran


 
 
manasi





PostPosted: SharePoint - Development and Programming, Sharepoint Blog - Comments Option Top

I want to do same thing.

I have a site on which people can post their ideas on a discussion board. The people that can post the ideas are valid users of the site. i.e. they have permission to contribute. But still they may choose to remain anonymous while posting the idea.

I have also created a colums that can have yes/no values for posting anonymously. When user checks the check box thereby choosing to post anonymously, i want to update 'Created By' column of the discussion board.

For this purpose, I have written and event handlers for ItemAdded and ItemUpdating event for the discussion board, in which I do following ( I have already added a user with user name "Anonymous")

Code Block

[SharePointPermission(SecurityAction.Assert, ObjectModel = true)]

public override void ItemAdded(SPItemEventProperties properties)

{

try

{

SPSecurity.RunWithElevatedPrivileges(delegate()

{

SPListItem currentItem = null;

SPWeb web = null;

//get the current list item which is to be added

currentItem = properties.ListItem;

//check Post Anonymous checkbox control

if (currentItem["Post_x0020_this_x0020_idea_x0020"] != null)

{

//check whether current list item is posted as anonymous

if (currentItem["Post_x0020_this_x0020_idea_x0020"].ToString().Equals("True"))

{

using (SPSite site = new SPSite(properties.WebUrl))

{

web = site.OpenWeb();

web.AllowUnsafeUpdates = true;

try

{

//get the anonymous user name from web.config file

string anonymousUserName = System.Configuration.ConfigurationSettings.AppSettings["AnonymousUserName"];

else

{

anonymousUserName = anonymousUserName.ToLower();

//iterate through the siteUsers collection.

foreach (SPUser siteUser in web.Users)

{

if ((siteUser.Name.ToLower()).Equals(anonymousUserName))

{

string userString = siteUser.ID + ";#" + siteUser.Name;

currentItem.Web.AllowUnsafeUpdates = true;

currentItem["Author"] = userString;

currentItem["Editor"] = userString;

currentItem.Update();

break;

}

}

}

catch (Exception exc)

{

Logger.Logger.LogError(HttpContext.Current, "PostAnonymousEventHandler", exc);

}

}

}

}

});

}

catch (Exception exc)

{

Logger.Logger.LogError(HttpContext.Current, "PostAnonymousEventHandler", exc);

}

}

public override void ItemUpdating(SPItemEventProperties properties)

{

SPListItem listItem = null;

int initial_Views_value = 0;

try

{

SPSecurity.RunWithElevatedPrivileges(delegate()

{

listItem = properties.ListItem;

string currUser = properties.UserLoginName;

if (listItem["Views"] != null)

{

// Get the initial value of "Views" field - i.e. before the item is viewed.

initial_Views_value = Int32.Parse(listItem["Views"].ToString());

// If no "Views" is found in AfterProperties return.

if ((properties.AfterProperties["Views"] == null))

{

return;

}

// When "Views" is found in AfterProperties change the "Editor" back to "Author".

else

{

if (Int32.Parse(properties.AfterProperties["Views"].ToString()) > initial_Views_value)

{

properties.AfterProperties["Editor"] = listItem["Author"];

}

}

}

// if no "Views" field is found - return.

else

{

return;

}

});

}

catch (Exception exc)

{

Logger.Logger.LogError(HttpContext.Current, "PostAnonymousEventHandler", exc);

}

}

All this code only works if the logged in user is the system account (or the primary site collection administrator) for all other users it fails. (even though i have used RunWithElevatedPrivileges).

How can i resolve this issue

Manasi


 
 
thekaran





PostPosted: SharePoint - Development and Programming, Sharepoint Blog - Comments Option Top

Manasi,

Try adding your "Anonymous" user account to site owner's list. I think that should fix the problem.

 
 
manasi





PostPosted: SharePoint - Development and Programming, Sharepoint Blog - Comments Option Top

I have already done that and it works fine for the system account but not for any other account.

I would also like to know if event handlers can work without installing the asembly in GAC.


 
 
Jigar32





PostPosted: SharePoint - Development and Programming, Sharepoint Blog - Comments Option Top

I am facing same problem. When I try to access RoleAssignments of my list or folder in ItemUpdating Handler, it throws exception of "you dont have access........."..

foreach (SPRoleAssignment assignment in destinationList.RoleAssignments)

{

if (assignment.Member.ToString() == properties.UserLoginName)

{

foreach (SPRoleDefinition spRoldeDef in assignment.RoleDefinitionBindings)

{

if (spRoldeDef.BasePermissions.ToString().Contains(SPBasePermissions.AddListItems.ToString()))

hasAccess = true;

}

}

}

Can you please help me in this

Thanks

Jigar



 
 
DonnaC30





PostPosted: SharePoint - Development and Programming, Sharepoint Blog - Comments Option Top

haven't used it myself, but this may work for you....

http://blogs.msdn.com/sharepoint/archive/2007/08/06/anonymous-comment-feature-for-sharepoint-blog-now-available-on-codeplex.aspx