Tuesday, 14 May 2013

SharePoint 13 – Workaround for – Sign in as Different User


Hello All,

I was doing some testing for my application and there is need for changing with different user who has different permission than the current logged in user. I clicked on current user in right top corner; pop appears but no “Sign in as Different User” option. So in SharePoint 2013 there is no “Sign in as Different User” option available as shown in following diagram




One possible solution is open new browser and log in with different user.  

But if we want to log in as different user in the same browser then other workaround is using direct URL in address browser, I opened my SP 2010 site and check the URL – _layouts/closeConnection.aspx?loginasanotheruser=true, I copied this URL and appended to my 2013 site url and it worked well.

Only thing SP 2013 added automatically 15 hive in URL so URL became _layouts/15/closeConnection.aspx?loginasanotheruser=true”.

Thanks!

Enjoy reading J

Feel free to comment / feedback if any or if you have any query J

Wednesday, 8 May 2013

Enabling the incoming email setting for custom generic list


Hello All,

In our one of the SharePoint 2010 project, we have one of the requirement is our custom list should receive an email and message from email should be updated in one of the list column.

Incoming e-mail settings option is enable under Communications column in list settings. 




1.       Document, picture, or form library
2.       Announcements list
3.       Calendar list
4.       Discussion board
5.       Blog


So here we have challenge to receive incoming emails for our custom list. After doing some research it found that if we associate SPEmailEventReceiver to my custom list, my list could also receive an email and “Incoming e-mail settings” will be available.

Following is the sample code where I have EmailEventReceiver class derived from SPEmailEventReceiver and override the EmailReceived method.

namespace MyNameSpace.EmailEventReceiver
{

    /// <summary>
    /// List Email Events
    /// </summary>
    public class EmailEventReceiver : SPEmailEventReceiver
    {
       /// <summary>
       /// The list received an e-mail message.
       /// </summary>
       public override void EmailReceived(SPList list, SPEmailMessage emailMessage, String receiverData)
       {
       }
   }
}

In above EmailReceived method,  SPEmailMessage contains all the details like Subject, Body etc.  We can read email subject and body as follows

//Email subject
string subject = emailMessage.Headers["Subject"];


//Email message in HTML format
string htmlBody = emailMessage.HtmlBody;

//Email message in Plain text format
string htmlBody = emailMessage.PlainTextBody;

Since I have created list through object model, I have associated above event receiver to my custom list as follows:

if (list != null){
   list.EventReceivers.Add(SPEventReceiverType.EmailReceived, "my fully qualiefied assembly name", "MyNameSpace.EmailEventReceiver.EmailEventReceiver");
   list.Update();
}

Thanks!

Enjoy reading J

Feel free to comment / feedback if any or if you have any query J






Monday, 6 May 2013

How to change the display name of OOB field "Title" using object model


Hello All,

Today I am going to post small and very simple post – “How to change the display name of OOB field "Title" using object model”. Since I struggled for some time to change the display name of OOB title column in one of the my custom list I thought I should share this J

In our project we have our custom list and list content type is derived from ITEM content type (0x01). So we have Title column from ITEM content type. But customer want to change the display name of Title column say “Customer Title”. So I thought I will simply do this change in my content and it will work like 

<FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" DisplayName="Customer Title" Required="TRUE"/>

But unfortunately it didn’t work. I did some research, some blogs says that change the display name in Schema.xml of list definition in <Fields> section for Title field but for us this is also not a solution since we have created our list using object model in FeatureActivated() of  our feature receiver. Again did some research and able to change the display name of OOB title column.  We could do this by updating “Title” property of respective SPField instance.

Following is the sample code

if (list.Fields.ContainsField("Title"))
                        {
                            SPField fldTitle = list.Fields["Title"];
                            fldTitle.Title = “My Custom DisplayName”;
                            fldTitle.Update(true);
                       
                        }

and following is the full code.

public class MyCustomerEventReceiver : SPFeatureReceiver
{

        #region Overload Methods
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;
            if (site != null) {
                SPWeb web = site.RootWeb;
                SPList list = web.Lists.TryGetList(“My Custom List”);
                bool flag = web.AllowUnsafeUpdates;
                    if (list == null)  {
                        web.AllowUnsafeUpdates = true;

Guid guid = web.Lists.Add(My Custom List, "Custom List", SPListTemplateType.GenericList);
                       
list = web.Lists[guid];
                       
                        if (list.Fields.ContainsField("Title"))
                        {
                            SPField fldTitle = list.Fields["Title"];
                            fldTitle.Title = “My Custom DisplayName”;
                            fldTitle.Update(true);
                       
                        }
list.Update();
}
              }
}

}

Thanks!

Enjoy reading J

Feel free to comment / feedback if any or if you have any query J