Posts

Showing posts with the label SharePoint Programming

SharePoint 2010 Modal Dialog Pop up

Modal Dialogs in SharePoint 2010 use the client library SP.UI.ModalDialog and ShowPopupDialog. We can open Dialog without leaving the page by writing simple html markup and by calling some SP.UI.ModalDialog API’s. Most simplest and an easy way to create SharePoint Modal Dialog is, calling JavaScript function and pass only URL parameter. <a href=”javascript:SP.UI.ModalDialog.ShowPopupDialog(‘/_layouts/viewlsts.aspx?isDlg=1′);” > View All Contents < /a> isDlg=1 Optional You can simply add “&IsDlg=1″ to any SharePoint URL and the chrome will be turned off. There are some parameters specially setting the width and the height of the window and a null parameter for call back function. which for now is set to null. We can create Dialog with specified hight and width like, < a href=”javascript:SP.UI.ModalDialog.ShowPopupDialog(‘/_layouts/viewlsts.aspx?isDlg=1′, null, 500, 300);” > View All Contents...

Send Mails in SharePoint Event Receiver

After I getting the user, email id from item( described in Previous Post) . Now I need to send mail to the user, I tried lot of ways to send mails and finally I realise that below code is best for my scenario to send mails. SmtpClient smtpClient = new SmtpClient(); smtpClient.Host = properties.Web.Site.WebApplication.OutboundMailServiceInstance.Server.Address; MailMessage mailMessage = new MailMessage(MailFrom, mailTo); mailMessage.Subject = MailSubject; mailMessage.Body = MailBody; mailMessage.IsBodyHtml = true; smtpClient.Send(mailMessage); here smtpClient.Host is getting the local mail server address and we include from, to and subject, body in MailMessage and finaly send the message using smtpClient.Send(mailMessage), and don’t forgot to include try catch blocks. Good luck.

Get user from Person or Group Field in Sharepoint List

There is a situation I need to add item to list and send mail to person who is on the same item xxxx field. Here xxxx is the person or group field and I set show field as “Name” [!i.e Display Name]   in list settings .   If we try to get values using properties.listItem[xxxx] it returns a junk characters with DisplayName and again we need remove the junk characters and query to user profiles to get the mail id. Sometimes [user profile not synchronized well] it didn’t query to get value based on “DisplayName”. So this situation I try to get the actual user of the filed instead of DisplayName. then i try the following code in event receiver.  SPFieldUser userField = (SPFieldUser)properties.OpenWeb().Lists[listName].Fields.GetField("xxxx"); SPFieldUserValue fieldValue=(SPFieldUserValue)userField.GetFieldValue(properties.ListItem["xxxx"].ToString()); accountName = fieldValue.User.LoginName; here fieldValue.User is SPUser,   the SPUser.logingName...

Show Application Page in SharePoint 2010 Modal PopUp

Recently i was creating SharePoint webpart here we need to show application page in popup. After a lot of time to searching finally we found SharePoint Popup model as solution. here we give the brief explanation of using SharePoint model popup. call the JavaScript method in your code and pass URL as parameter as shown in below code.   <a href="javascript:OpenDialog(_layouts/xxxxxx/xxxxx.aspx');">MyPopUp</a> implement JavaScript method, in that calling sharepoint inbuilt method show model dialog as shown in below code. <script type="text/javascript">     function OpenDialog(URL)  {         var NewPopUp = SP.UI.$create_DialogOptions();         NewPopUp.url = URL;         NewPopUp.width = 400;         NewPopUp.height = 250;         SP.UI.Mo...

Custom SharePoint Timer Job

Know more about Timer Job A timer job runs in a specific Windows service for SharePoint Server. Timer jobs also perform infrastructure tasks for the Timer service, such as clearing the timer job history and recycling the Timer service; and tasks for Web applications, such as sending e-mail alerts. A timer job contains a definition of the service to run and specifies how frequently the service is started. The SharePoint 2010 Timer service (SPTimerv4) runs timer jobs. Many features in SharePoint Server rely on timer jobs to run services according to a schedule. For custom timer job creation need to follow the below steps or procedures: - Inherit class from SPJobDefintion (using Microsoft.SharePoint.Administration) - Creatig Timer Job in feature activated event receiver as per specifications as shown in below code //Create class derived from SPJonDefinition Class  class ListTimerJob : SPJobDefinition     {        ...