Subscribe:

Labels

Friday, July 12, 2013

Implement the Custom "Like" and "Rating" functionality in Share Point 2013

If u want implement custom Like and Rating functionality in Sharepoint 2013,find the below code.
Add Microsoft.Office.Server.UserProfiles.dll as a reference in your project
Class: Following are the classes which are available with the namespace
Reputation,ElevatedPrivilegesHelper

Set Custom Like for ur Sharepoint List or Library

SPList resourceList = SPContext.Current.Web.Lists["Resources"];
SPListItem likeItem = resourceList.Items[0];
Reputation.SetLike(resourceList.ID.ToString(), likeItem.ID, true);

Set custom Rating for ur List or Library

SPList resourceList = SPContext.Current.Web.Lists["Resources"];
SPListItem likeItem = resourceList.Items[0];
Reputation.SetRating(resourceList.ID.ToString(), likeItem.ID, 4);

Before this code you have to enable the Rating and Like functionality on ur sharepoint list...
Goto List settings u will find Rating settings.
once u enable this automatically some fields are created to ur list
Those are
LikedBy
LikesCount
etc

Same thing u can implement using client side object model code

var likepage = {
//Likes the current page.
LikePage: function () {
likepage.getUserLikedPage(function(likedPage, likeCount) {
var aContextObject = new SP.ClientContext();
EnsureScriptFunc('reputation.js', 'Microsoft.Office.Server.ReputationModel.Reputation', function() {
Microsoft.Office.Server.ReputationModel.
Reputation.setLike(aContextObject,
_spPageContextInfo.pageListId.substring(1, 37),
_spPageContextInfo.pageItemId, !likedPage);
aContextObject.executeQueryAsync(
function() {
var elements = document.getElementsByClassName('likecount');
if (likedPage) {
likeCount--;
} else {
likeCount++;
}
for (var i = 0; i < elements.length;i++) {
elements[i].innerHTML = likeCount;
}
}, function(sender, args) {
// Custom error handling if needed
});
});
});
},
// Checks if the user already liked the page, and returns the number of likes.
getUserLikedPage: function (cb) {
var context = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl);
var list = context.get_web().get_lists().getById(_spPageContextInfo.pageListId);
var item = list.getItemById(_spPageContextInfo.pageItemId);
context.load(item, "LikedBy", "ID", "LikesCount");
context.executeQueryAsync(Function.createDelegate(this, function (success) {
// Check if the user id of the current users is in the collection LikedBy.
var $v_0 = item.get_item('LikedBy');
if (!SP.ScriptHelpers.isNullOrUndefined($v_0)) {
for (var $v_1 = 0, $v_2 = $v_0.length; $v_1 < $v_2; $v_1++) {
var $v_3 = $v_0[$v_1];
if ($v_3.$1E_1 === _spPageContextInfo.userId) {
cb(true, item.get_item('LikesCount'));
}
}
}
cb(false, item.get_item('LikesCount'));
}),
Function.createDelegate(this, function (sender, args) { //Custom error handling if needed }));
},
initialize: function () {
var elements = document.getElementsByClassName('likecount');
likepage.getUserLikedPage(function(likedPage, likesCount) {
for (var i = 0; i < elements.length; i++) {
elements[i].innerHTML = likesCount;
}
});
}
};
_spBodyOnLoadFunctionNames.push("likepage.initialize");

Thursday, June 20, 2013

Export to excel from Data table in C#

 public void ExporttoExcel()
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.ClearHeaders();
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.ContentType = "application/ms-excel";
            HttpContext.Current.Response.Write(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">");
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=Reports.xls");

            HttpContext.Current.Response.Charset = "utf-8";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");
            //sets font
            HttpContext.Current.Response.Write("<font style='font-size:10.0pt; font-family:Calibri;'>");
            HttpContext.Current.Response.Write("<BR><BR><BR>");
            //sets the table border, cell spacing, border color, font of the text, background, foreground, font height
            HttpContext.Current.Response.Write("<Table border='1' bgColor='#ffffff' " +
              "borderColor='#000000' cellSpacing='0' cellPadding='0' " +
              "style='font-size:10.0pt; font-family:Calibri; background:white;'> <TR>");
            //am getting my grid's column headers
           // int columnscount = GridView_Result.Columns.Count;
            for (int i = 0; i < grdViewYMP.Columns.Count ; i++)
            {
                HttpContext.Current.Response.Write("<Td>");
                //Get column headers  and make it as bold in excel columns
                HttpContext.Current.Response.Write("<B>");
                HttpContext.Current.Response.Write(grdViewYMP.HeaderRow.Cells[i].Text.Trim());
                HttpContext.Current.Response.Write("</B>");
                HttpContext.Current.Response.Write("</Td>");
            }
            HttpContext.Current.Response.Write("</TR>");
            DataTable dtYMP = ViewState["dtYMP"] as DataTable;
                                           
            foreach (DataRow row in dtYMP.Rows)
            {//write in new row
                HttpContext.Current.Response.Write("<TR>");
                for (int i = 0; i < dtYMP.Columns.Count; i++)
                {
                    HttpContext.Current.Response.Write("<Td>");
                    HttpContext.Current.Response.Write(row[i].ToString());
                    HttpContext.Current.Response.Write("</Td>");
                }

                HttpContext.Current.Response.Write("</TR>");
            }
            HttpContext.Current.Response.Write("</Table>");
            HttpContext.Current.Response.Write("</font>");
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }        

Export to Excel functionality Using Office.Interop.excel referenc

public void ExporExcelusingOffice()
        {
            // creating Excel Application

            Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();

            // creating new WorkBook within Excel application

            Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);

            // creating new Excelsheet in workbook

            Microsoft.Office.Interop.Excel._Worksheet worksheet = null;

            // see the excel sheet behind the program
            app.Visible = true;

            // get the reference of first sheet. By default its name is Sheet1.

            // store its reference to worksheet

            worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets["Sheet1"];

            worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.ActiveSheet;

            // changing the name of active sheet

            worksheet.Name = "Exported from gridview";


            // storing header part in Excel

            for (int i = 1; i < grdViewYMP.Columns.Count + 1; i++)
            {
                worksheet.Cells[1, i] = grdViewYMP.HeaderRow.Cells[i - 1].Text.Trim();
            }

            DataTable dtYMP = ViewState["dtYMP"] as DataTable;


            // storing Each row and column value to excel sheet

            for (int i = 0; i < grdViewYMP.Rows.Count - 1; i++)
            {
                for (int j = 0; j < grdViewYMP.Columns.Count; j++)
                {
                    worksheet.Cells[i + 2, j + 1] = dtYMP.Rows[i][j].ToString();
                    //worksheet.Cells[i + 2, j + 1] = grdViewYMP.Rows[i].Cells[j].Text;
                }
            }

            // save the application
            object misValue = System.Reflection.Missing.Value;
            // workbook.SaveAs("c:\\output.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            workbook.SaveAs("c:\\YMPoutput.xlsx", Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel9795, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared, misValue, misValue, misValue, misValue, misValue);
            // Exit from the application

            app.Quit();

        }

Monday, June 3, 2013

Create a mysite(personal site) Using the Object Model


Below code is using object model creating the my sites dynamically.


            SPSite site = new SPSite("http://win-rgqt3bch3nk:22929/sites/Test");

            SPWeb web = site.OpenWeb();
            // SPWeb web = SPContext.Current.Web;


            web.AllowUnsafeUpdates = true;

         
            if (ApproveitemId > 0)
            {
                SPList thislist = web.Lists["Requests"];
                SPListItem item = thislist.Items.GetItemById(ApproveitemId);
                string AStatus = item["Approval_Status"].ToString();
                string strYes = "Yes";
                if (AStatus == strYes)
                {
                    string mysiteusername = item["Username"].ToString();
                     //SPUser mysiteuname = web.AllUsers[mysiteusername];

                    SPSecurity.RunWithElevatedPrivileges(delegate()
                         {
                             using (SPSite spSite = new SPSite("http://win-rgqt3bch3nk:38562"))
                             {
                                 spSite.AllowUnsafeUpdates = true;
                                 SPContext.Current.Web.AllowUnsafeUpdates = true;
                                 SPServiceContext siteContext = SPServiceContext.GetContext(spSite);
                                 //UserProfileManager up = new UserProfileManager(siteContext,true);
                                 UserProfileManager up = new UserProfileManager(siteContext);
                                 //string sAccount = "WIN-RGQT3BCH3NK\\test1";
                                 //UserProfile uprof = up.GetUserProfile(sAccount.Trim());
                                 UserProfile uprof = up.GetUserProfile(mysiteusername);
                                 uprof.CreatePersonalSite();
                             }
                         });
                }
            }
         
        }

DB Upgrade for migrating from SharePoint 2007 to SharePoint 2010

Find the following Steps which we used for the Intranet Migration

We used DB Upgrade for migrating the Intranet environment from SharePoint 2007 to SharePoint 2010.
  
  1.    Run the PreUpgrade check in SharePoint 2007
  2.    Resolve the errors
  3.    Installed the SharePoint 2010 in the new SharePoint Farm environment
  4.    Configured the SharePoint farm
  5.     Copied the DBs from SP 2007 DB to SP 2010 DB
  6.   Configured the Service Applications
  7.   Installed the customizations(wsps)
  8.  Created all the Web Applications in SP 2010 with test DB
  9.  Checked the DB upgrade errors using test-mount
  10.  Upgraded the Web App DBs using PowerShell
  11.   Upgraded the Customizations
  12.  Changed the Web Sites(Site Collections and Sub Sites) UI from SP 2007 to SP2010
  13.    Configured the Search Service app
  14.    Configured the User profile app and Synchronized the users from AD



Friday, May 24, 2013

Is Number and Decimal validation in Javascript for Text box control OnKeyPress and OnBlurr functions



<asp:TextBox ID="txtBxRouteNote2" runat="server" Text='<%#Eval("RouteNote2")%>' onblur="return extractNumber(this,2,true);"    onkeyPress="return isNumberKey(event)"></asp:TextBox>



 function extractNumber(obj, decimalPlaces, allowNegative) {
        //debugger;
        var temp = obj.value;

        // avoid changing things if already formatted correctly
        var reg0Str = '[0-9]*';
        if (decimalPlaces > 0) {
            reg0Str += '\[\,\.]?[0-9]{0,' + decimalPlaces + '}';
        } else if (decimalPlaces < 0) {
            reg0Str += '\[\,\.]?[0-9]*';
        }
        reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
        reg0Str = reg0Str + '$';
        var reg0 = new RegExp(reg0Str);
        if (reg0.test(temp)) return true;

        // first replace all non numbers
        var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (decimalPlaces != 0 ? ',' : '') + (allowNegative ? '-' : '') + ']';
        var reg1 = new RegExp(reg1Str, 'g');
        temp = temp.replace(reg1, '');

        if (allowNegative) {
            // replace extra negative
            var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
            var reg2 = /-/g;
            temp = temp.replace(reg2, '');
            if (hasNegative) temp = '-' + temp;
        }

        if (decimalPlaces != 0) {
            var reg3 = /[\,\.]/g;
            var reg3Array = reg3.exec(temp);
            if (reg3Array != null) {
                // keep only first occurrence of .
                //  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
                var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
                reg3Right = reg3Right.replace(reg3, '');
                reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
                temp = temp.substring(0, reg3Array.index) + '.' + reg3Right;
            }
        }

        if (temp < 999.99) {
            obj.value = temp;
        }
        else {
            obj.value = '';
            alert("Please enter the values between 00.00 to 999.99");
        }
    }






 function isNumberKey(evt) {
        //debugger;
        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46)
            return false;
    }


Wednesday, February 6, 2013

To develop Dash boards using PPS in sharepoint 2010

Steps:

  1. Configure Secure store Service in SA
  2. Create Performance point Services
  3. Configure PPS with Secure store Account 
  4. Do the Performance Point Service Application Settings 
  5. Create a Site Collection with Business Intelligent Center template 
  6. In this Site collection Create one list and library those are 
  7. Performance point list 
  8. Data connection library
  9. After this u need create new connection in Data connection library 
  10. In performance point list u need click on the new item. 
  11. If it 1st time it will run Dashboard desighner window to install. 
  12. It will open the Dashboard designer 
  13. In this Designer u need to create according to ur req. 
  14. Like Scorecard or KPI or Filter or Reports etc. 
  15. If u can select Score Card it will ask to select the data source. 
  16. In after this u can design based on the dimensions and measure.
These are major steps to create Dashboards using PPS (Performance point service) in sharepoint 2010