Showing posts from 2013

How to run SharePoint code with Elevated Privileges ?What are the security risks in it ?

SharePoint elevated privileges, site collection administrator code RunWithElevatedPrivileges is a class in SharePoint which comes under SPSecurity namespace. It allows developers to create the code that runs as the System Account instead of the logged in user, essentially giving that user Administrator Level Permissions in a specific space. So there is a question that, Run with elevated privileges can create high security risk ? Security risk is very minimal as the user will only have permission to do exactly what the developer will allow them through the code. Here is a syntax for that:

 private void yourFunction() 
 // Non-Elevated Permission Code Goes Here 
 { // Elevated Permission Code Goes Here }); // Non-Elevated Permission Code Goes Here }

Upload images and show the list of image in gridview to code

Below code will upload image in a particular folder and will show the list of images from that folder. User may delete images from that list.

HTML Code:

        <table style="width: 90%">
                <td style="width: 50%">
                    File Upload with Thumbnail Generator:<br />
                    <asp:FileUpload ID="FileUpload1" runat="server" /><br />
                    <asp:Button ID="buttonUpload" runat="server" Text="Upload" OnClick="buttonUpload_Click" /><br />
                <td style="width: 50%">
                    <asp:GridView ID="UploadedFiles" DataSource="<%# GetUploadList() %>" runat="server"
                        CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDeleting="UploadedFiles_…

Java Script Form Validation

Form validation is a process by which users are restrict to enter irrelevant data. For eg invalid format of email id, alphabets in mobile no.l field.

Below is the code to validate a form. Below function can be call either on a button click or on an anchor link.

  function Validation() {
            var regexMobile = /^[7-9][0-9]{9}$/;
            var regexNumberCount = /^\d{10}$/;
            var regexpincode = /^[1-9][0-9]{5}$/;
            var regexemailid = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;

            var name = document.getElementById('<%=txtName.ClientID %>');
            var mobile = document.getElementById('<%=txtMoile.ClientID %>');
            var address = document.getElementById('<%=txtareaAddress.ClientID %>');
            var email = document.getElementById('<%=txtEmail.ClientID %>');
            var pincode = document.getElementById('<%=txtPincode.ClientID %>');
            var ddlO…

Timer job in SharePoint 2010. How to create a timer job?

What is Timer Job in SharePoint - Timer Jobs are background processes that are managed by SharePoint. Timer job runs on a periodic basis defined in central admin.
Timer job runs periodically , can be scheduled hourly, daily, weekly.
Ex: User profile sync, Search Indexing

Timer job is a class which implements the SPJobDefinition class.
Timer job override the Execute method of SPJobDefinition class.

Timer Job Implementation and Code:

Follow below steps to implement Timer Job in SharePoint 2010.
Create a SharePoint Project in Visual Studio 2010.
Add a class in project.

class MyTimerJob : SPJobDefinition
        public MyTimerJob () : base() { }

        public MyTimerJob (string jobName, SPService service) :
            base(jobName, service, null, SPJobLockType.None)
            this.Title = "Task Complete";

        public MyTimerJob (string jobName, SPWebApplication webapp) :
            base(jobName, webapp, null, SPJobLockType.ContentDatabase)

How to export subsites or list in sharepoint 2010?

Some times you need to take the backup of your subsites with all pages, list and library. Subsites can not be taken as backup and restore. Subsite can be exported and imported to another site.

First you need to export the subsite. So to do that Go to central admin, Click on backup and restore, then "Export a site or list" as shown in below screen.

Export subsite

Then select your site collection, after that select your subsite and give a file name for ex- musubsiteexport. Leave other things as usual and click on start export and wait for completion.

subiste, list sharepoint 2010

Gridview row edit, delete and update code in

As Gridview is a data source control which binds data from backend sql server or any other database table. Here is the code which implements edit, delete and update functionality in a single Gridview.

Gridview Edit,Update and Delete functionality code:

ASPX Code:

<asp:GridView ID="gvDetails" DataKeyNames="id" runat="server" AutoGenerateColumns="false"
                    CssClass="Gridview" HeaderStyle-BackColor="Blue" Width="90%" ShowFooter="true"
                    HeaderStyle-Font-Bold="true" HeaderStyle-ForeColor="White" OnRowCancelingEdit="gvDetails_RowCancelingEdit"
                    OnRowDeleting="gvDetails_RowDeleting" OnRowEditing="gvDetails_RowEditing" OnRowUpdating="gvDetails_RowUpdating"