Interview Questions administrator

Best SharePoint administrator Interview Questions and Answers with topic wise:


Recycle Bin | MMS | ManagedVsCrawledProperties |
Showing posts with label Sharepoint2007. Show all posts
Showing posts with label Sharepoint2007. Show all posts

Sunday, December 2, 2012

SPField’s to the dropdown List programmatically:


By default, we can get the number of built-in fields or internal fields if you try to retrieve the fields in a list. My below post will help to add only the custom fields to the dropdown list by avoiding all the internal, built-in and hidden fields.

using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
    SPWeb web = site.OpenWeb(SPContext.Current.Web.ID);
    web.AllowUnsafeUpdates = true;
    SPList list = web.Lists[new Guid(listId)];
    var fields = from SPField f in list.Fields
                        where !f.Hidden && f.AuthoringInfo == "" &&
                                      f.Type != SPFieldType.Attachments &&
                                      f.Type != SPFieldType.WorkflowStatus
                        orderby f.Title
                        select new { ListItem = new ListItem(f.Title, f.Id.ToString()),
                                               Readonly = f.ReadOnlyField, FieldType = f.Type };

ddlDestfield.DataSource = from g in fields where !g.Readonly &&
(g.FieldType == SPFieldType.Note || g.FieldType == SPFieldType.Text)                                                select g.ListItem;
ddlDestfield.DataBind();
ddlDestfield.Items.Insert(0, new ListItem("[Select]", "none"));
}


Note: Set f.AuthoringInfo == null [In SP2007] and Set f.AuthoringInfo == "" [In SP2010]

Wednesday, August 29, 2012

Adding/Removing users to/from the group:

Note: We have to check before adding/removing users to/from the group and also check the users already exists or not in group. 
 
public void AddDeleteUsersInGroup(User user)
        {
            string GroupName = string.Empty;
            if (user.IsAdmin.HasValue && user.IsAdmin.Value)
                GroupName = "Group Owners";
            else if (user.IsApprover.HasValue && user.IsApprover.Value)
                GroupName = " Group Members";
            else
                GroupName = " Group Visitors";

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        try
                        {
                            web.AllowUnsafeUpdates = true;
                            SPUser spUser = web.EnsureUser(user.UserName);
                            if (spUser != null)
                            {
                                SPGroup spGroup = spGatingGroup(web, GroupName);
                                if (spGroup != null && (IsUserInSPGroup(spUser, GroupName.Trim())))
                                {
                                   //For adding user to the group
                                      spGroup.AddUser(spUser);
                                   //For removing user to the group
                                    spGroup.RemoveUser(spUser);
                                    spGroup.Update();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            web.AllowUnsafeUpdates = false;
                        }
                    }
                }
            });
        }
 

Sunday, March 4, 2012

When/where/why use "AllowUnsafeUpdates" in SharePoint?


As per msdn articleAllowUnsafeUpdates is set to true when you are trying to update the database as a result of the GET request”. 

E.g. Say you have a list and you want to update something to the SharePoint data [content DB], then you need to set AllowUnsafeUpdates = true for the web and after you have done you need to set it back to false. 

What will happen if you set as AllowUnsafeUpdates to false? And what is preventing it from cross site scripting attacks?  Yes, the FormDigest control is taking care of all about it. I have already explained about “FormDigest’ control in previous post. Please go through to get more on it here. 

To GET the content from the content DB, we need to set the AllowUnsafeUpdates = true. 
To POST the content to the content DB, not require to set the AllowUnsafeUpdates = true. why means because of "FormDigest" control placed in every master page.

Thursday, February 23, 2012

Faster way to search the items in a sharepoint list and libraries:


Using the URL to sort or filter a list or library [or] Filter a SharePoint List with Query String Parameters

Did you know that you easily can filter your SharePoint list or library with values in your URL? That means without using “Views “option. This one’s very useful when you’re having a lot of items in a list or document library and you need a quick filter.

The syntax is as follows:

< URL to List or Library >/Forms/AllItems.aspx?FilterField[X]=[Column to Filter]&FilterValue[X]=[Value]
·          
       [X] is the number of filter's you're applying.  The first set will always be 1, the next set 2, etc.
·         [Column to Filter] is the internal name of the column you wish to filter, such as Title.
·         [Value] is the value you wish to filter on.