sharepointeventreceiver

Anchor Tag Not working in Event Receiver


I have created an event receiver to trigger an e-mail whenever an item was added.in this event receiver email gets deliverd to the employee. In the e-mail content i would like to give a link so that the employee can go to the web site directly. but in my code i am facing some problem . here is my code

public string MailMsgBody_WU(string MailTo, SPItemEventProperties IERProperties)
   {
       string MMsgBody = "";

       System.Diagnostics.Debug.WriteLine("Travel Request-MailMsgBody(): Begin");
       try
       {

           MMsgBody += "<table>";
           MMsgBody += "<tr><td>Hi,</td></tr>";
           MMsgBody += "<tr><td><br></br></td></tr>";
           MMsgBody += "<tr><td> New Calendar Item Event" + IERProperties.ListTitle + " has been added into learning portal.</td></tr>";
           MMsgBody += "<tr><td><br></br></td></tr>";
           MMsgBody += "<tr><td>Please click on the following link to view the details.</td></tr>";
           MMsgBody += "<tr><td><br></br></td></tr>";
           MMsgBody += "<tr><td><a href=" + http://tri02sharepoint:47709/Lists/Learning%20Calendar/calendar.aspx    + ">Click Here</a></td></tr>";           
           MMsgBody += "<tr><td><br></br></td></tr>";
           MMsgBody += "<tr><td><br></br></td></tr>";
           MMsgBody += "<tr><td>Thanks,</td></tr>";
           MMsgBody += "<tr><td>Learning Team</td></tr>";
           MMsgBody += "</table>";

       }
       catch (Exception ex)
       {
           System.Diagnostics.Debug.WriteLine("Travel Request-MailMsgBody(): End" + ex.Message.ToString());
       }
       return MMsgBody;
   }

i am getting the error in
MMsgBody += "<tr><td><a href=" + http://tri02sharepoint:47709/Lists/Learning%20Calendar/calendar.aspx + ">Click Here</a></td></tr>";

http:// <---- here is the Error

These are the errors

Error 1 Invalid expression term ':'
Error 2 ; expected
Error 3 ; expected


Solution

  • You can't do this:

    MMsgBody += "<tr><td><a href=" + http://tri02sharepoint:47709/Lists/Learning%20Calendar/calendar.aspx    + ">Click Here</a></td></tr>";
    

    You are basically trying to call a function/field/member called "http://tri02sharepoint..." within your C# code, which obviously does not exist.

    You should do this instead:

    MMsgBody += "<tr><td><a href=\"http://tri02sharepoint:47709/Lists/Learning%20Calendar/calendar.aspx\">Click Here</a></td></tr>";
    

    You need to escape special characters like " and you do that with a \.