contact / feedback webpart. I think call out is better then this one.

How to Create The Contact/feedback Web part in SharePoint 2010


Contact Feedback Webpart in Sharepoint 2010

This article will show, step-by-step, how to create simple visual web part that implements a contact feedback form. A contact feedback form is typically used on a public website to provide a way for customers, business partners, and others outside the company to submit questions or request information by filling out fields on a web page and clicking a Submit button. This web part will collect the user’s name, email address, and message, and send the information to an email address when the user clicks Submit.

The web part created in this article will use Sharepoint 2010. To create the web part, we will be using Visual Studio 2010 installed on Windows Server 2008.

Design the Webpart:

Add the following code in your webpart(Design Mode)

< style type="text/css"> span.required    { color: #FF0000; font-size: 12px; white-space: nowrap; padding-right: 3px;    } .data    { color: #000000; font-family: Arial,Helvetica,sans-serif; font-size: 12px; font-weight:bold; padding-left: 3px; line-height: 20px; vertical-align: top; text-align: left;    } .error    { color: #000000; font-family: Arial,Helvetica,sans-serif; font-size: 12px;    } .test    { color: #000000; font-family: Arial,Helvetica,sans-serif; font-size: 12px; padding-right: 10px;    } table.ms-toolbar    { background-color: #EBF3FF; background-repeat: repeat; border: 1pxsolid#BFBFBF;    } .ms-formbody    { background: nonerepeatscroll00#EBF3FF; border-top: 1pxsolid#D8D8D8; font-family: verdana; font-size: 0.7em; padding: 3px6px4px; vertical-align: top;    } .ms-formbody    { background: nonerepeatscroll00#EFEFEF;    } </ style > < div style="text-align: left;"> <tablecellpadding="2"cellspacing="0"border="0"width="100%"> <tralign="right"> <tdcolspan="2"> <tableclass="ms-toolbar"align="center"cellpadding="0"cellspacing="0"width="100%"> <tr> <td> <spanclass="required">* </span><spanclass="test">indicates a required field</span> </td> </tr> </table> </td> </tr> <tr> <tdwidth="100%"> <tablealign="center"cellpadding="0"cellspacing="0"width="100%"> <tr> <tdclass="data"> <%--<asp:Label ID="lblname" Text="Your Name" runat="server"></asp:Label>--%>                            Your Name <spanclass="required">*</span> </td> <tdclass="ms-formbody"> <divstyle="width: 100%"> <asp:TextBoxID="txtName"runat="server"Width="450px"></asp:TextBox></div> <asp:RequiredFieldValidatorID="rfvYourName"runat="server"ControlToValidate="txtName" ErrorMessage="Please Enter Your Name."SetFocusOnError="True"ToolTip="Please Enter Your Name." Display="Dynamic"></asp:RequiredFieldValidator> </td> </tr> <tr> <tdclass="data">                            Your E-mail <spanclass="required">*</span> <%--<asp:Label ID="Label1" Text="Your E-mail" runat="server"></asp:Label>--%> </td> <tdclass="ms-formbody"> <divstyle="width: 100%"> <asp:TextBoxID="txtEmail"runat="server"Width="450px"></asp:TextBox></div> <asp:RequiredFieldValidatorID="rfvtxtEmail"runat="server"ControlToValidate="txtEmail" ErrorMessage="Please Enter Your Email."SetFocusOnError="True"ToolTip="Please Enter Your Email." Display="Dynamic"></asp:RequiredFieldValidator> <asp:RegularExpressionValidatorID="revtxtEmail"runat="server"ErrorMessage="You must sepcify a valid email id" ControlToValidate="txtEmail"Display="Dynamic"SetFocusOnError="True"ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator> </td> </tr> <tr> <tdclass="data">                            Subject </td> <tdclass="ms-formbody"> <divstyle="width: 100%"> <asp:TextBoxID="txtSubject"runat="server"Width="450px"></asp:TextBox></div> </td> </tr> <tr> <tdclass="data">                            Message <spanclass="required">*</span> </td> <tdclass="ms-formbody"> <divstyle="width: 100%"> <asp:TextBoxID="txtMessage"runat="server"TextMode="MultiLine"Height="100px"Rows="5" Width="450px"></asp:TextBox></div> <asp:RequiredFieldValidatorID="rfvmessage"runat="server"ControlToValidate="txtMessage" ErrorMessage="Please Enter The Message."SetFocusOnError="True"ToolTip="Please Enter The Message." Display="Dynamic"></asp:RequiredFieldValidator> </td> </tr> <tr> <tdclass="data">                            Attachments </td> <tdclass="ms-formbody"> <divstyle="width: 100%"> <asp:FileUploadID="oFileUpload"runat="server"Width="450px"/></div> </td> </tr> <tr> <tdcolspan="1"> </td> <tdalign="right"style="padding-top: 20px; padding-bottom: 20px;"> <asp:ButtonID="btnSend"runat="server"Text="Send"OnClick="btnSend_Click"Style="margin-left: 0px" Width="75px"/> </td> </tr> <tr> <tdcolspan="2"> <asp:LabelID="lblMessage"runat="server"Text=""></asp:Label> </td> </tr> </table> </td> </tr> </table> </ div >
Modify your styles and validation expressions according to your logic. Development: using System; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Runtime.InteropServices; using System.Xml.Serialization; using System.ComponentModel; using System.Net.Mail; using System.IO; using System.Net; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; namespace ContactFeedback.Contact_Feedback_Form { publicpartialclassContact_Feedback_FormUserControl : UserControl    { // System.Collections.Specialized.StringDictionary oMessageHeader; Label oLabelValidMessage; protectedvoid Page_Load(object sender, EventArgs e)        {        } publicstring ReceipientsEmails        { get; set;        } protectedvoid btnSend_Click(object sender, EventArgs e)        {            oLabelValidMessage = newLabel(); //oLabelValidMessage.ID = "lbl_validmessage"; this.Controls.Add(oLabelValidMessage); if (ReceipientsEmails !="")            { string ValidateReceipEmailId = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";                System.Text.RegularExpressions.Regex oRegvReceipEMail = newSystem.Text.RegularExpressions.Regex(ValidateReceipEmailId); if (!oRegvReceipEMail.IsMatch(ReceipientsEmails))                {                    oLabelValidMessage.Visible = true;                    oLabelValidMessage.Text = "You must specify a valid E-mail address in webpart properties"; return;                } //if (txtName.Text == "" || txtEmail.Text == "" || txtMessage.Text == "") //{ //    lblValidMessage.Visible = true; //    lblValidMessage.Text = "You must specify a value for required field"; //    return; //} //string ValidateSenderEmailId = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"; //System.Text.RegularExpressions.Regex oRegvSenderEMail = new System.Text.RegularExpressions.Regex(ValidateSenderEmailId); //if (!oRegvSenderEMail.IsMatch(txtEmail.Text)) //{ //    lblValidMessage.Visible = true; //    lblValidMessage.Text = "You must sepcify a valid email id"; //    return; //} try                { //oMessageHeader = new System.Collections.Specialized.StringDictionary(); //oMessageHeader.Add("To", ReceipientsEmail); //oMessageHeader.Add("From", oTextEMail.Text); //oMessageHeader.Add("Subject", oTextSubject.Text); //oMessageHeader.Add("content-type", "text/plain"); //oMessageHeader.Add("FileUpload", oFileUpload.FileName); //string oMessageBody = oTextMessage.Text.ToString(); //Microsoft.SharePoint.Utilities.SPUtility.SendEmail(SPContext.Current.Web, oMessageHeader, oMessageBody); SmtpClient Client = LoadSmtpInformation();                    Client.Send(BuildMailMessage(ReceipientsEmails, txtEmail.Text, txtSubject.Text, txtMessage.Text));                    lblMessage.Visible = true;                    lblMessage.Text = "Message Sent";                } catch (Exception ex)                {                    lblMessage.Text = ex.ToString();                }            }        } privateSmtpClient LoadSmtpInformation()        { string smtpServer =SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address; string smtpFrom =SPAdministrationWebApplication.Local.OutboundMailSenderAddress; SmtpClient client = newSmtpClient(smtpServer);            client.Credentials = CredentialCache.DefaultNetworkCredentials; return client;        } privateMailMessage BuildMailMessage(string strTo, string strFrom, stringstrSubject, string strContenttype)        { MailMessage message = newMailMessage();            message.From = newMailAddress(strFrom);            message.To.Add(newMailAddress(strTo));            message.IsBodyHtml = true;            message.Body = strContenttype;            message.Subject = strSubject; if (oFileUpload.FileContent.Length > 0)            message.Attachments.Add(newAttachment(oFileUpload.FileContent, oFileUpload.FileName)); return message;        }    } } Add the Webpart Properties(.cs file) using System; using System.ComponentModel; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; namespace ContactFeedback.Contact_Feedback_Form {    [ToolboxItemAttribute(false)] publicclassContact_Feedback_Form : WebPart    { // Visual Studio might automatically update this path when you change the Visual Web Part project item. privateconststring _ascxPath =@"~/_CONTROLTEMPLATES/ContactFeedback/Contact_Feedback_Form/Contact_Feedback_FormUserControl.ascx"; privatestring _ReceipientsEmail = string.Empty;        [WebBrowsable(true)]        [Personalizable(PersonalizationScope.Shared)]        [WebDescription("Send To EMail")]        [Category("Receipents EMail")]        [WebDisplayName("Email")]       publicstring ReceipientsEmail        { get { return _ReceipientsEmail; } set { _ReceipientsEmail = value; }        } protectedoverridevoid CreateChildControls()        { //ontrol control = Page.LoadControl(_ascxPath); Contact_Feedback_FormUserControl control = (Contact_Feedback_FormUserControl)Page.LoadControl("~/_CONTROLTEMPLATES/ContactFeedback/Contact_Feedback_Form/Contact_Feedback_FormUserControl.ascx");            control.ReceipientsEmails = ReceipientsEmail;            Controls.Add(control);        }    } }

Deploying the Webpart: Using Stsadm
C:\>stsadm -o addsolution -filename ContactFormWebPart.wsp C:\>stsadm -o deploysolution -name ContactFormWebPart.wsp -immediate           -allowgacdeployment �Callcontenturls
Using powershell Add-SPSolution C:\ContactFeedback.wsp Install-SPSolution -Identity ContactFeedback.wsp -WebApplication http://devsps2010.abc.com/ �CGACDeployment
Checking the Outgoing Email Settings:

Add your webpart on your page Add the Webpart properties:


Done..


你可能感兴趣的:(request,article,contact,Business,customers)