Microsoft Power Platform, SharePoint, Azure, AWS, Google Cloud, DevOps, AI/ML
Saturday, July 27, 2013
Build CAML Query Dynamically based on Passing Parameters to the Query in SharePoint.
string camlQuery = CreateCAMLQuery(parameters);
private static string CreateCAMLQuery(string[] parameters)
{
StringBuilder sb = new StringBuilder();
if (parameters.Length == 0)
{
AppendEQ(sb, "all", "all");
}
for (int i = 0; i < parameters.Length; i += 2)
{
AppendEQ(sb, parameters[i], parameters[i + 1]);
if (i > 0)
{
sb.Insert(0, "<And>");
sb.Append("</And>");
}
}
sb.Insert(0, "<Where>");
sb.Append("</Where>");
return sb.ToString();
}
private static void AppendEQ(StringBuilder sb, string column, string value)
{
sb.Append("<Eq>");
if (column == "state")
{
sb.Append("<FieldRef Name='state'/>");
sb.AppendFormat("<Value Type='Lookup'>{0}</Value>", value);
}
if (column == "City")
{
sb.Append("<FieldRef Name='City'/>");
sb.AppendFormat("<Value Type='Lookup'>{0}</Value>", value);
}
if (column == "VehicleMake")
{
sb.Append("<FieldRef Name='VehicleMake'/>");
sb.AppendFormat("<Value Type='Choice'>{0}</Value>", value);
}
if (column == "GarageType")
{
sb.Append("<FieldRef Name='GarageType'/>");
sb.AppendFormat("<Value Type='Choice'>{0}</Value>", value);
}
sb.Append("</Eq>");
}
Rating WebPart using AverageRatingFieldControl in SharePoint
1. Add Rating on a Layout Page:-
--------------------------------------------
1. Open any layout page add below ‘Rate this article” div code
<asp:content contentplaceholderid=" PlaceHolderMain" runat="server">
<div class="welcome blank-wp">
<div>
Rate this article:
<SharePointPortalControls:Aver ageRatingFieldControl
ID="PageRatingControl"
FieldName="AverageRating"
runat="server"/>
</div>
2. Enable rating feature for a pages list form list settings.
3. Open a page which using page layout having rating field control
4. Give the rating on page and go to list page and check. Total no.of ratings is increased.

----------------------------------------------------------------------------------------------------------------------------------------------------
2. Rating WebPart in SharePoint:-
--------------------------------------------------
RatingVisualWebPart.ascx:-
--------------------------
<%@ Assembly Name="$SharePoint.Project. AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken= 71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft. SharePoint.WebControls"Assembly="Microsoft. SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken= 71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft. SharePoint.Utilities"Assembly="Microsoft. SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken= 71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web. Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken= 31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft. SharePoint" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft. SharePoint.WebPartPages"Assembly="Microsoft. SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken= 71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind=" RatingVisualWebPart.ascx.cs" Inherits="Rating. RatingVisualWebPart. RatingVisualWebPart"%>
<%@ Register TagPrefix=" SharePointPortalControls"
Namespace="Microsoft. SharePoint.Portal.WebControls"
Assembly="Microsoft. SharePoint.Portal, Version=14.0.0.0,Culture= neutral,PublicKeyToken= 71e9bce111e9429c" %>
<%--<span class="content_small_text">
<SharePointPortalControls: averageratingfieldcontrol id="rating" runat="server" controlmode="Edit"/>
</span>--%>
<span class="content_small_text">
<asp:Panel ID="pnl1" runat="server">
</asp:Panel>
</span>
RatingVisualWebPart.ascx.cs:-
----------------------------------------------
using System;
using System.ComponentModel;
using System.Web.UI.WebControls. WebParts;
using Microsoft.SharePoint.Portal;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Portal. WebControls;
using Microsoft.SharePoint. WebControls;
using System.Web;
namespace Rating.RatingVisualWebPart
{
[ToolboxItemAttribute(false)]
public partial class RatingVisualWebPart : WebPart
{
public RatingVisualWebPart()
{ }
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
InitializeControl();
}
protected void Page_Load(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
SPList testList = SPContext.Current.Web.Lists. TryGetList("Pages");
SPListItem testItem = testList.GetItemById(249);
AverageRatingFieldControl ratingCntrl = new AverageRatingFieldControl();
ratingCntrl.ID = "RatingCntrl";
ratingCntrl.ListId = testList.ID;
ratingCntrl.ControlMode = SPControlMode.Edit;
ratingCntrl.FieldName = "AverageRating";
ratingCntrl.ItemContext = SPContext.GetContext(context, testItem.ID, testList.ID, SPContext.Current.Web);
pnl1.Controls.Add(ratingCntrl) ;
AverageRatingFieldControl arfcRating = new AverageRatingFieldControl();
arfcRating.ID = "rating";
arfcRating.ListId = testList.ID;
arfcRating.FieldName = "Rating (0-5)";
arfcRating.ControlMode = SPControlMode.Edit;
arfcRating.ItemContext = SPContext.GetContext(context, testItem.ID,testItem.ParentList.ID, testItem.ListItems.List. ParentWeb);
pnl1.Controls.Add(arfcRating);
}
}
}
Send E-Mail from C# Code
try
{
StringBuilder strMailContent = new StringBuilder();
MailMessage mail = new MailMessage();
String strMessage = "Test Message from C# Code";
String strSMTPAddress = "xxx.xxx.xxx.xxx";
String strUserName = "domain_forest_name";
String strPassword = "domain_pwd";
String strDomain = "domain_name";
mail.To.Add(toName);
mail.From = new MailAddress(fromName);
mail.Subject = "test mail from C# code. " +DateTime.Now.ToString("F"); //("MMM ddd d HH:mm yyyy");
strMailContent.Append("<html>< body><table>");
strMailContent.Append("<tr>< td>Dear " + toName + "</td></tr>");
strMailContent.Append("</ table>");
strMailContent.Append("</body> </html></table>");
mail.Body = strMailContent.ToString();
SmtpClient smtp = new SmtpClient(strSMTPAddress);
smtp.Credentials = new System.Net.NetworkCredential( strUserName, strPassword, strDomain);
smtp.Send(mail);
}
catch (Exception ex) {
SPDiagnosticsService diagnosticsService = SPDiagnosticsService.Local;
string errorMsg = ex.Message;
diagnosticsService.WriteTrace( 0, new SPDiagnosticsCategory(" AleartSettingTimerJob", TraceSeverity.Monitorable, EventSeverity.Error),TraceSeverity.Monitorable, "Writing to the ULS log: {0}", new object[] { errorMsg });
diagnosticsService.WriteEvent( 0, new SPDiagnosticsCategory(" AleartSettingTimerJob", TraceSeverity.Monitorable, EventSeverity.Error),EventSeverity.Error, "Writing to the Event Viewer log: {0}", new object[] { errorMsg });
}
Send SMS to mobile form C# Code
Send SMS to mobile form C# Code:-
---------------------------------
String uName = "uname";
String pwd = "password";
String strSender = "";
string PhNo = "";
string Msg = "Text Message 160 plain characters";
String strErrMsg = "";
string url = "http://www.unicel.in/SendSMS/ sendmsg.php?uname=" + uName + "&pass=" + pwd + "&send=" + strSender + "&dest=91" + PhNo.ToString() + "&msg=" + Msg.ToString();
HttpWebRequest request = (HttpWebRequest)WebRequest. Create(url);
HttpWebResponse response = (HttpWebResponse)request. GetResponse();
String ver = response.ProtocolVersion. ToString();
StreamReader reader = new StreamReader(response. GetResponseStream());
strErrMsg = reader.ReadLine();
reader.Close();
--------------------------------------------------------------------------------------------
Subscribe to:
Posts (Atom)
Featured Post
Building Secure APIs with FastAPI and Azure AD Authentication
Building Secure APIs with FastAPI and Azure AD Authentication Published on September 2, 2025 In today's world of microservices and API-f...
Popular posts
-
CAML:- --------- <Where> <IsNotNull> <FieldRef Name='ID' /> </IsNotNull> ...
-
WebForm1.aspx:- ------------------------- <% @ Page Language ="C#" AutoEventWireup ="true" CodeBehind ="...
-
This operation can be performed only on a computer that is joined to a server farm by users who have permissions in SQL Server to read from...
-
Authorize Postman to access SharePoint 1. Register Add-In 2. Grant Permissions to Add-In 3. Generate the Access Token 4. Access th...
-
CreateDocumentSet.aspx <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %> <%@ Import Namesp...
-
Reading an excel file using HTML 5 and jQuery and save in SharePoint list Reference https://github.com/SheetJS/js-xlsx https://github.co...
-
Read SharePoint list Items using REST API and ReactJS Step1: Create a "ReactDemo" list and list columns as shown below. ...
-
Read excel data from document library saving as list items using CSOM in SharePoint. 1. Upload an excel file into Document library. This ...
-
CAML Query filter between two dates Method 1:- </And><Geq><FieldRef Name='Created' /><Value Type='Date...