Sunday, October 28, 2012

Enable/Disable Developer Dashboard Powershell command SharePoint 2010

Type below commands in Powershell

$service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$addsetting =$service.DeveloperDashboardSettings
$addsetting.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::On
$addsetting.Update()


Make it OnDemand


$service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$addsetting =$service.DeveloperDashboardSettings
$addsetting.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::OnDemand
$addsetting.Update()


Turn Off

$service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$addsetting =$service.DeveloperDashboardSettings
$addsetting.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::Off
$addsetting.Update()

Tuesday, September 25, 2012

Write to workflow history list state machine workflow sharepoint 2010 C# code

void WriteToHistoryList(string comment, string outcome)
        {
            SPWorkflow.CreateHistoryEvent(workflowProperties.Web, this.WorkflowInstanceId, 0, workflowProperties.Web.CurrentUser, new TimeSpan(), outcome, comment, "");
        }

Wednesday, September 12, 2012

Make Column Read Only Sharepoint 2010

PS C:\Users\gadekasa> $spWeb = Get-SPWeb http://abc:5552/sites/AirCraft/
PS C:\Users\gadekasa> $spList = $spWeb.Lists["AllWorkflowDefaultList"]
PS C:\Users\gadekasa> $fields =$spList.Fields["Role"]
PS C:\Users\gadekasa> $fields.ReadOnlyField = $false
PS C:\Users\gadekasa> $fields.update($true)
PS C:\Users\gadekasa> $spList.Update()
PS C:\Users\gadekasa> $spWeb.Dispose()

Saturday, August 25, 2012

Adding Custom CSS style in Markup drop down of Sharepoint 2010 HTML editor ribbon




1. Create one css file in 14 hive(you can add it in your visual studio solution by adding layouts mapped folder)

2. add below css class in that file 

/* custom style in */
DIV.ms-rteElement-mkg-H1
{
-ms-name: "marketing-header";
color: #d65c26;
font-family: Verdana,Geneva,sans-serif;
font-weight: normal;
font-size: 2em;
}

Saturday, August 11, 2012

WCF with sharepoint 2010 service

Try below code, it works perfectly fine:-

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Linq;
using Microsoft.SharePoint.Linq;
using WCFService.ListWCFService;
namespace WCFService.WP_WCFService
{
    public partial class WP_WCFServiceUserControl : UserControl
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }
        protected override void OnPreRender(EventArgs e)
        {
            try
            {
                System.Uri uri = new Uri("http://localhost:16178/_vti_bin/ListData.svc");
               SrgDataContext dc = new SrgDataContext(uri);
               dc.Credentials = System.Net.CredentialCache.DefaultCredentials;
                    var query = from dev in dc.Announcements
                                select new
                                {
                                    Title = dev.Title,
                                    Body = dev.Body,
                                    ExpiryDate = dev.Expires,
                                    Path = dev.Path
                                };
                    gridAnnouncementList.DataSource = query;
                    gridAnnouncementList.DataBind();
             
                //dc.Dispose();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
           

Using Sharepoint rich text box in Web Part

Just add below line in sharepoint project visual web part ascx file:-
<SharePoint:InputFormTextBox runat="server" ID="txtBody" TextMode="MultiLine" ValidationGroup="CreateCase" Rows="8" Columns="40" RichText="true" RichTextMode="FullHtml" AllowHyperlink="true" />

Saturday, June 23, 2012

On Enter Button click redirect with querystring as textbox value


put your text box and button in panel with default button

<asp:Panel  DefaultButton="Button1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </asp:Panel >





OR





<script>

     function button_click(objTextBox, objBtnID) {
         if (window.event.keyCode == 13) {
             if (objTextBox.value != "") {
                 document.getElementById(objBtnID).focus();
                 document.getElementById(objBtnID).click();
             }
            
         }
      }
    </script>



<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />




Page load:-
this.TextBox1.Attributes.Add("onkeypress", "button_click(this,'" + this.Button1.ClientID + "')");


protected void Button1_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(TextBox1.Text))
        {
            Response.Redirect("Default2.aspx?text=" + TextBox1.Text);
        }
    }

SharePoint document metadata not updating

I faced a weird issue today, Metadata for document which has lookup column was not updating even after saving the item. There was no erro...