Thursday, December 28, 2017

Close SharePoint Pop-up window

 Context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup()</script>");
            Context.Response.Flush();
            Context.Response.End();

Wednesday, November 1, 2017

Installing and configuring Workflow for SharePoint Server 2013

When you open SharePoint Designer 2013 connected to a site to build a workflow, you will notice a new option called platform type. If it’s only “SharePoint 2010 Workflow” that you see, you need to install and configure “workflow manager”.

As MSDN recommends, you need to consider the following two key factors before configuring Workflow Manager to work with SharePoint Server 2013.
  • Is Workflow Manager installed on a server that is part of the SharePoint farm?
  • Will communication between Workflow Manager and SharePoint Server 2013 use HTTP or HTTPS?
These factors translate into four scenarios. Each scenario configures a SharePoint Server 2013 farm to communicate and function with the Workflow Manager farm. Follow the scenario that matches your circumstance.
  1. Workflow Manager is installed on a server that is part of the SharePoint 2013 farm. Communication takes place by using HTTP.
  2. Workflow Manager is installed on a server that is part of the SharePoint 2013 farm. Communication takes place by using HTTPS.
  3. Workflow Manager is installed on a server that is NOT part of the SharePoint 2013 farm. Communication takes place by using HTTP.
  4. Workflow Manager is installed on a server that is NOT part of the SharePoint 2013 farm. Communication takes place by using HTTPS.
Mine is the 1st scenario. Workflow Manager can be downloaded from here. Workflow Manager installation uses Web Platform Installer as shown in the below screen.
image
image
Then you need to install the prerequisites.
image
image
image
Clicking continue will bring the configuration options.
image
I prefer to go with the custom setting as I can get to know what’s going on behind scene. If you select the “Configure Workflow Manager with Default Settings (Recommended)”, it will install a Workflow Manager farm. So let’s move with custom :)
In the below screen you need to specify the database server, where it will create the DBs needed for WM(Workflow Manager).
image
Make sure you remember or keep safe the Certificate Generation Key, as it’s needed when you want to add more servers to the WM farm.
image
Service account will be used to run the Application pool of the WM Website.
image
Below screen looks nice so added that too :D
image
image
image
image
Three screens below show the full configuration summary.
image
image
image
You can even see the full PowerShell script for the configuration.
image
image
image
image
Great!! You are done with the installation and the configuration of Workflow Manager. Yet one more step left for the Workflows to work in 2013 Platform. Open IIS Manager to see the WM Site and the port you configured.
image
Open SharePoint Management Shell with Admin rights and execute the below cmdlet (replacing the site and the Workflow Manager host site).
Register-SPWorkflowService –SPSite "http://www.whiteknight.com/Hr" –WorkflowHostUri "http://workflow.whiteknight.com:12291" –AllowOAuthHttp
Finally to check whether everything works fine… Open the above site (registered with workflow host uri) in SharePoint Designer 2013 and check the Platform type in workflow.
Workflow Manager 1.0
When you install Workflow Manager on a WFE it automatically installs the Workflow Manager Client on that WFE. You will still need to install the Workflow Manager Client on any additional WFE servers.
---------------------------------------------------------------------------------------------------------------------

Source: http://prabathf.blogspot.com/2013/02/installing-and-configuring-workflow-for.html 

Send Email C#

MailMessage Mail = new MailMessage("email", SPuser.User.Email);
Mail.Subject = " ";
Mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("")
                                {
                                    DeliveryMethod = SmtpDeliveryMethod.Network,
                                    Credentials = new NetworkCredential()
                                };
                                smtp.EnableSsl = false;
                                smtp.Send(Mail);

Tuesday, October 10, 2017

Dynamically create CAML query

public string GenerateQuery(IList<CamlQueryElements> lstOfElement)
    {
        StringBuilder queryJoin = new StringBuilder();
        string query = @"<{0}><FieldRef Name='{1}' /><Value {2} Type='{3}'>{4}</Value></Eq>";
        if (lstOfElement.Count > 0)
        {
            int itemCount = 0;
            foreach (CamlQueryElements element in lstOfElement)
            {
                itemCount++;
                string date = string.Empty;
                // Display only Date
                if (String.Compare(element.FieldType, "DateTime", true) == 0)
                    date = "IncludeTimeValue='false'";
                queryJoin.AppendFormat(string.Format(query, element.ComparisonOperators,
                                element.FieldName, date, element.FieldType, element.FieldValue));

                if (itemCount >= 2)
                {
                    queryJoin.Insert(0, string.Format("<{0}>", element.LogicalJoin));
                    queryJoin.Append(string.Format("</{0}>", element.LogicalJoin));
                }
            }
            queryJoin.Insert(0, "<Where>");
            queryJoin.Append("</Where>");
        }
        return queryJoin.ToString();
    }

source: https://stackoverflow.com/questions/8267515/dynamically-create-caml-query?rq=1 

Tuesday, September 26, 2017

Error in displaying the custom Content type of each list

I have created several custom lists in my project and I affected to each one a custom content type.
After deploying the project and exploring my SharePoint site , there is only one content type which is added to all list instances.
I'm sure that the schema.xml of each list contains its custom content type ( ID and fields ).
Am I missing something else in my Project?
Can anyone help me please?

solution:
The problem is resolved when I put each List Definition in a separate feature .
At first time , I used to put all List Definitions in the same feature , then I put the ID of this feature in element.xml file of each list Instance as featureId Attribute .
Automatically , each list instance references to the first List Definition of the feature , then it displays the fields and the content type related to this list Definition .

source: https://stackoverflow.com/questions/25114501/error-in-displaying-the-custom-content-type-of-each-list 

Wednesday, March 29, 2017

Get People Picker Field Value

ClientContext clientContext = new ClientContext("url");
List listInstance = clientContext.Web.Lists.GetByTitle("list name");
ListItem item = listInstance .GetItemById(list id);
clientContext.Load(item);
FieldUserValue userValue = item["user type field internal name"] as FieldUserValue;
clientContext.ExecuteQuery();
string username = userValue.LookupValue.ToSTring();
----------------------------------------------------------------------------------------------------------
source: https://social.technet.microsoft.com/Forums/Windows/en-US/3d367e58-91ec-4547-8e55-f1635eaec5bf/how-to-get-value-from-people-picker-field-using-c-in-sharepoint-2010?forum=sharepointdevelopmentprevious

Wednesday, March 22, 2017

ASP.NET pie chart control

<asp:Chart ID="ChartFarmProfile" runat="server" Width="450px">
<Series>
<asp:Series Name="Series3">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea3">
<AxisX>
<MajorGrid Enabled="False" />
</AxisX>
<AxisY>
<MajorGrid Enabled="False" />
</AxisY>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>

if (DtPlotCrop.Rows.Count > 0)
                    {

                        DataView dv = DtPlotCrop.Rows[0].Table.DefaultView;
                        ChartCropProfile.Series["Series3"].Points.DataBindXY(dv, "Crop_Name", dv, "CropArea");

                        ChartCropProfile.Series["Series3"].ChartType = SeriesChartType.Pie;

                        ChartCropProfile.Series["Series3"]["PointWidth"] = "0.5";
                        ChartCropProfile.Series["Series3"].IsValueShownAsLabel = true;
                        ChartCropProfile.Series["Series3"].Label = "#VALY " + DtPlotCrop.Rows[0]["Unit"];
                        ChartCropProfile.Series["Series3"]["BarLabelStyle"] = "Center";
                        ChartCropProfile.ChartAreas["ChartArea3"].Area3DStyle.Enable3D = true;
                        ChartCropProfile.Series["Series3"]["DrawingStyle"] = "Cylinder";
                        ChartCropProfile.Series["Series3"]["LineColor"] = "Black";
                        ChartCropProfile.Series["Series3"]["LabelStyle"] = "Outside";
                        
                        ChartCropProfile.Series["Series3"].ToolTip = "#VALX (#VALY " + DtPlotCrop.Rows[0]["Unit"] + ")"+ "#PERCENT";

                        ChartCropProfile.Series["Series3"].BackGradientStyle = GradientStyle.DiagonalLeft;
                        ChartCropProfile.Series["Series3"].BackSecondaryColor = System.Drawing.Color.LightGray;



                        ChartCropProfile.Legends.Add(new Legend("Profile"));
                        ChartCropProfile.Legends["Profile"].Title = "Crop Name (Area)";
                        ChartCropProfile.Series[0].LegendText = "#VALX (#VALY " + DtPlotCrop.Rows[0]["Unit"] + ")";

                        ChartCropProfile.Legends[0].TableStyle = LegendTableStyle.Wide;
                        ChartCropProfile.Legends[0].Docking = Docking.Bottom;


                    }

HOW TO RECOVER THE SQL DATABASE FROM SUSPECT MODE (Or) HOW TO BRING BACK THE SUSPECTED DATABASE TO THE NORMAL MODE When you logi...