Wednesday, March 23, 2016

Multiple files upload and formdata using dropzone js

DropzoneJS is an open source library that provides drag and drop files upload with image preview.


Dropzone supports drag and drop functionality for thumbnail image, multiple uploads and progress bar which can be integrated with MVC.

This blog  is an  example of multiple files upload with form data and without form data.We can fetch response from the controller action and we can mold it any form while showing it on client side.Errors can also be Received in  response.

How to install in your application.

Add stylesheet and Jqeury for Dropzone JS
            

            
            
You can also add cdn for stylesheet and .js file from this link :Click Here.
Add two images for display upload files image.

How to use it in application.

Add form tag in your html body and add class dropzone to form tag.
            

How to use dropzone js with form data.

 
First Name
Last Name
Registration Number
 
 

Add this script in your html page.


            

Add action method in you controller.

Add this mehtod in your controller. Dropzone file upload using ajax and pass form parameter in post call. In that call you can get model data and your uploaded files.
            [HttpPost]
            public ActionResult SaveFilesAndData(StudentModel model)
            {
                try
                {
                    HttpFileCollectionBase filesData = Request.Files;//Here you can get multiple files.
                    for (int i = 0; i < filesData.Count; i++)
                    {
                        //This code for save your file in directory
                        HttpPostedFileBase file = Request.Files[i];
                        //Save file content goes here
                        if (file != null && file.ContentLength > 0)
                        {
                            string path = Server.MapPath(@"~/DropjoneImages/");
                            bool isExists = System.IO.Directory.Exists(path);
                            if (!isExists)
                                System.IO.Directory.CreateDirectory(path);
                            file.SaveAs(path + file.FileName);
                        }
                    }
                    return Json(new { success = true, message = "" }, JsonRequestBehavior.AllowGet);
                }
                catch (Exception ex)
                {
                    return Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet);
                }
            }
            
Note : Dropjonne js is provide others good configuration properties using that you can achive your requirement.
Here i have attached my screen shot for upload file and form data.
Here i have attached screen shot for get data in controller.

Browser Support

  • Chrome 7+
  • Firefox 4+
  • IE 10+
  • Opera 10+(Version 12 for MacOS is disabled because their API is buggy)
  • Safari 6+

Friday, September 5, 2014

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Query2
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnExecute_Click(object sender, EventArgs e)
        {
            string query = string.Empty;
            query = txtQuery.Text.Trim();
            ClsManager obj = new ClsManager();
            IExecuteQuery execute = (IExecuteQuery)obj;
            try
            {
                if (query.Length > 0)
                {
                    if (query.ToLower().StartsWith("select"))
                    {
                        DataSet ds = new DataSet();
                        ds = execute.GetQueryResult(query);
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            ViewState["SortExpr"] = null;
                            gv.DataSource = ds;
                            gv.DataBind();
                        }
                        else
                        {
                            lblMsg.Visible = true;
                            lblMsg.Text = "No Record Found";                
                        }
                    }
                    else
                    {
                        lblMsg.Visible = true;
                        lblMsg.Text = "Please Enter Valid Select Query.";        
                    }

                }
                else
                {
                    lblMsg.Visible = true;
                    lblMsg.Text = "Please Enter Query.";
                }
            }
            catch (Exception)
            {
                lblMsg.Visible = true;
                lblMsg.Text = obj.SqlEception;
            }
 
        }

        

        protected void gv_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            string query = string.Empty;
            query = txtQuery.Text.Trim();
            ClsManager obj = new ClsManager();
            IExecuteQuery execute = (IExecuteQuery)obj;
            gv.PageIndex = e.NewPageIndex;
            DataSet ds = new DataSet();
            ds = execute.GetQueryResult(query);
            if (ds.Tables[0].Rows.Count > 0)
            {
                gv.DataSource = ds;
                gv.DataBind();
            }
            else
            {
                lblMsg.Visible = true;
                lblMsg.Text = "No Record Found";
            }

        }

        protected void gv_Sorting(object sender, GridViewSortEventArgs e)
        {
            if (ViewState["sortexpre"] == null)
            {


                string[] sortorder = ViewState["sortexpre"].ToString().Split(',');
                if (sortorder[0] == e.SortExpression)
                {
                    if (sortorder[1] == "ASC")
                    {
                        ViewState["sortexpre"] = e.SortExpression + " " + "DESC";

                    }
                    else
                    {
                        ViewState["sortexpre"] = e.SortExpression + " " + "ASC";
                    }

                }
                else
                {
                    ViewState["sortexpre"] = e.SortExpression + " " + "ASC";
                }
                string query = string.Empty;
                query = txtQuery.Text.Trim();
                ClsManager obj = new ClsManager();
                IExecuteQuery execute = (IExecuteQuery)obj;
                DataSet ds = new DataSet();
                ds = execute.GetQueryResult(query);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    gv.DataSource = ds;
                    gv.DataBind();
                }
                else
                {
                    lblMsg.Visible = true;
                    lblMsg.Text = "No Record Found";
                }
            }
        }
    }
}



Wednesday, August 13, 2014

How to create dropdownlist with filter and multiselect.

In this article i have post for dropdownlist with multiple selection with filter using bootstrap.

this example also help for ASP.NET application. 
Add thease scripts and css on your page.
  
    
    
    
    
    
    


Add this div on your page.
  
 
Add this code in your c#(.cs) page.
 

 protected void Page_Load(object sender, EventArgs e)
 {
     ddlProduct.Attributes["multiple"] = "multiple";
     if (!Page.IsPostBack)
     {
        BindData();
     }
}

private void BindData()
{
    List product =new List();
    product.Add(new ProductDetails { Id = 1, Name = "Books" });
    product.Add(new ProductDetails { Id = 2, Name = "Shoes" });
    product.Add(new ProductDetails { Id = 3, Name = "Computer" });
    product.Add(new ProductDetails { Id = 4, Name = "Pen" });
    product.Add(new ProductDetails { Id = 5, Name = "LCD" });
    product.Add(new ProductDetails { Id = 6, Name = "TV" });
    product.Add(new ProductDetails { Id = 7, Name = "Laptop" });
    product.Add(new ProductDetails { Id = 8, Name = "Bags" });
    ddlProduct.DataSource = product;
    ddlProduct.DataTextField = "Name";
    ddlProduct.DataValueField = "Id";
    ddlProduct.DataBind();
}

public class ProductDetails
{
    public int Id { get; set; }

    public string Name { get; set; }
}

Preview Of this example.

Friday, March 14, 2014

Find nth highest salary from employee using sql query.

Hi Friend here i am provide you MSsql query to find nth highest salary. lots of example to find nth highest salary but here i am giving you a only two example. 1
  
         SELECT * FROM emp  Emp1
         WHERE ( n ) = (
                         SELECT COUNT( DISTINCT ( Emp2.salary ) )
                         FROM emp  Emp2
                         WHERE Emp2.salary >= Emp1.salary
                        )
    
  
    Select TOP 1 salary as '3rd Highest Salary' from (SELECT DISTINCT TOP 3 salary from emp ORDER BY salary DESC)
    a ORDER BY salary ASC 

Thursday, March 6, 2014

Create Database Table Field Properties Using Sql Sciprt

This Script Is Help to you for Create Sql Server Database Table Field Properties for your project. And also help to create Entity for you table.
  
Use DatabaseName

DECLARE @TableName VARCHAR(MAX) = 'TableName'
DECLARE @TableSchema VARCHAR(MAX) = 'Schema'
DECLARE @result varchar(max) = ''

SET @result = @result + 'using System;' + CHAR(13) + CHAR(13) 

IF (@TableSchema IS NOT NULL) 
BEGIN
    SET @result = @result + 'namespace ' + @TableSchema  + CHAR(13) + '{' + CHAR(13) 
END

SET @result = @result + 'public class ' + @TableName + CHAR(13) + '{' + CHAR(13) 

SET @result = @result + '#region Properties' + CHAR(13)  

SELECT @result = @result + CHAR(13) 
    + ' public ' + ColumnType + ' ' + ColumnName + ' { get; set; } ' + CHAR(13) 
FROM
(
    SELECT  c.COLUMN_NAME   AS ColumnName 
        , CASE c.DATA_TYPE   
            WHEN 'bigint' THEN
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'Int64?' ELSE 'Int64' END
            WHEN 'binary' THEN 'Byte[]'
            WHEN 'bit' THEN 
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'bool?' ELSE 'bool' END            
            WHEN 'char' THEN 'string'
            WHEN 'date' THEN
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'DateTime?' ELSE 'DateTime' END                        
            WHEN 'datetime' THEN
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'DateTime?' ELSE 'DateTime' END                        
            WHEN 'datetime2' THEN  
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'DateTime?' ELSE 'DateTime' END                        
            WHEN 'datetimeoffset' THEN 
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'DateTimeOffset?' ELSE 'DateTimeOffset' END                                    
            WHEN 'decimal' THEN  
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'Decimal?' ELSE 'Decimal' END                                    
            WHEN 'float' THEN 
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'Single?' ELSE 'Single' END                                    
            WHEN 'image' THEN 'Byte[]'
            WHEN 'int' THEN  
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'Int32?' ELSE 'Int32' END
            WHEN 'money' THEN
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'Decimal?' ELSE 'Decimal' END                                                
            WHEN 'nchar' THEN 'string'
            WHEN 'ntext' THEN 'string'
            WHEN 'numeric' THEN
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'Decimal?' ELSE 'Decimal' END                                                            
            WHEN 'nvarchar' THEN 'string'
            WHEN 'real' THEN 
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'Double?' ELSE 'Double' END                                                                        
            WHEN 'smalldatetime' THEN 
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'DateTime?' ELSE 'DateTime' END                                    
            WHEN 'smallint' THEN 
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'Int16?' ELSE 'Int16'END            
            WHEN 'smallmoney' THEN  
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'Decimal?' ELSE 'Decimal' END                                                                        
            WHEN 'text' THEN 'string'
            WHEN 'time' THEN 
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'TimeSpan?' ELSE 'TimeSpan' END                                                                                    
            WHEN 'timestamp' THEN 
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'DateTime?' ELSE 'DateTime' END                                    
            WHEN 'tinyint' THEN 
                CASE C.IS_NULLABLE
                    WHEN 'YES' THEN 'Byte?' ELSE 'Byte' END                                                
            WHEN 'uniqueidentifier' THEN 'Guid'
            WHEN 'varbinary' THEN 'Byte[]'
            WHEN 'varchar' THEN 'string'
            ELSE 'Object'
        END AS ColumnType
        , c.ORDINAL_POSITION 
FROM    INFORMATION_SCHEMA.COLUMNS c
WHERE   c.TABLE_NAME = @TableName and ISNULL(@TableSchema, c.TABLE_SCHEMA) = c.TABLE_SCHEMA  
) t
ORDER BY t.ORDINAL_POSITION

SET @result = @result + CHAR(13) + '#endregion Properties' + CHAR(13)  

SET @result = @result  + '}' + CHAR(13)

IF (@TableSchema IS NOT NULL) 
BEGIN
    SET @result = @result + CHAR(13) + '}' 
END

PRINT @result

Thursday, December 19, 2013

Interview qustion for .net devloper.

  1. Gridview itemtemplate textboox value is lost after postBack? 
  2. not in instead of EXCEPT example. 
  3. what is _dopostback? 
  4. Inumerable and iquerable? 
  5. Authentication? 
  6. examples of joins with Linq quey? 
  7. what is active directory? 
  8. what is index and its types? 
  9. database constraint? 
  10. why we use interface? 
  11. why we use abstract class? 
  12. types of wcf bindings? 
  13. Difference between webfarm and webgarden? 
  14. what is singleton? 
  15. diff. bet on and live? 
  16. what is trigger in jquery?
  17.  jquery events load sequence one by one? 
  18. Types of WCF Contract? 
  19. string inbuit functions Details and its function Details?
  20.  types of design Pattern(Microsoft enterprise library)?
  21.  what is deadlock in WCF? 
  22. what is difference between lambda expression query and normal linq qury?
  23.  how to works page postback? 
  24. how to use override method in class? 
  25. describe events and delegate? 
  26. why we use interface in WCF? 
  27. difference between WCF and Web-Api? 
  28. what is event bubbling? 
  29. Database Constraint?
  30.  Indexing in SQL Serve? 
  31. Write Ajax call syntax using Jquery?
  32.  types of session and maximum timeout of session? 
  33. postback on dropdownlist select value 2 and 3? 
  34. What is data annotation in MVC?
  35.  what is inheritance?
  36. which is faster between array and List? 
  37. what is abstraction? 
  38. parameters type in sql? 
  39. can we use optional parameter in sql server? 
  40. what is filestream in sql?
  41.  how can we use exception handling in SQL? 
  42. What is State management? 
  43. What is Authentication and Authorization? 
  44. Explain globalization? 
  45. types of assembly? 
  46. What is Strong name?
  47.  what is singlton?
  48.  What is SQL Profiler? 
  49. What is postback and page render, explain? 
  50. Explain page lifecycle of asp.net?
  51. How to maintaining session in WEB Garden?
  52.  What is SOA, give example? 
  53. What is Object pooling, explain the diff parameter? 
  54. diff of .net framework? 
  55. what is static method? 
  56. what is application pool in IIS? 
  57. What is IIS? Benefits of the store procedure? 
  58. what is index and its type briefly? 
  59. what is ovveride?
  60.  what is worker process in IIS? 
  61. diff. bet gridview and repeater? 
  62. describe chance to loss session variable? 
  63. what is SOAP? 
  64. what is SOA? 
  65. IIS ANd Sql Server Default port? 
  66. difference between string and string in c#? 
  67. difference between string and stringbuilder?
  68.  ADO.NET(Connected and Disconnected Architecture)? 
  69. What is Linkded Server in Sql Server? 
  70. Why Application pool in not(3.5,4.5)? 
  71. Difference between bit tinyint smallint int and bigint datatypes in SQL Server?
  72.  Difference between Read only, Constant, and static? 
  73. difference between array and arraylist in c#? 
  74. difference between arrayList and list in c#? 
  75. what is anonymous methods in c#? 
  76. what are jquery selectors? 
  77. difference between class and structure? 
  78. what is difference between dynamic and var in c#?
  79. can we set Session value from JavaScript?
  80. Drawback of Json?
  81. why json faster than XML?
  82. What  is trigger and its types?
  83. difference between $.ajax and $.post?
  84. yield in c sharp?
  85. What is DBMS? 
  86. What is RDBMS? 
  87. DBMS vs RDBMS ?
  88. difference between usercontrol and custom control?
  89. What are constructors and destructors?
  90. What is the difference between CONST and READONLY?
  91. What is the difference between Array and LinkedList?
  92. What is the use of goto statement?
  93. What is the difference between break and continue statement?
  94. What is the use of using statement in C#?
  95. difference between ref and out parameter in c#
  96. difference between destroy and finalize?
  97. threading pool in c#
  98. select ''+null output?
  99. joins in linq?
  100. ipc binding in wcf?
  101. types of errors in c sharp?
  102. C sharp Properties?
  103. Sql Xml Path Query?
  104. cache and its type and where it is stored?
  105. Asp.Net and Mvc Difference?
  106. Types of Constructor?
  107. types of access modifiers in c#  
  108. session management
  109. Action filter
  110. authorization
  111. display view
  112. how to manage form authentication and window authentication
  113. html helper and editor/item template difference
  114. what is routing
  115. what is partial view
  116. render partial and partial
  117. how to use session in MVC?
  118. what is area?
  119. sealed method
  120. what is iis isolation?
  121. what ioc and dependency injection c#?
  122. wcf behavior?
  123. wcf dift dift bindingd use?
  124. difference betn architecture and framework?
  125. what is factory pattern?
  126. what is desing pattern?
  127. what is microsoft class library?
  128. difference between datacontract and operationcontract in wcf?
  129. difference between datacontract and message contract in wcf?
  130. wcf serialization?
  131. difference between var and dynamic keyword in c#
  132. How to manage sessionstate in controller.
  133. What is Remote validation in MVC?
  134. What is HTML Helper in MVC? 
  135. How to validate Model From server side?
  136. diff between for and while loop.
  137. diff between for-each and while loop.
  138. why we use var and what is purpose of that?
  139. difference between architecture and framework?
  140. why multiple inheritance not supported in c#?
  141. Swap number in C#?
  142. Difference between private and public constructor. 
  143. What childactiononly in MVC?

Thursday, November 28, 2013

Add GridView Row Without PostBack And Get value using Jquery AutoComplete

  
    
    
    
    
    
Add Html Code
  

    
AutoComplete Demo With Editable Html Grid
Yor Product Name :
       
  
 [System.Web.Services.WebMethod]
        public static string CalledPageMethod(string jsonString, string total)
        {
            JsonSerializer json = new JsonSerializer();

            List sdf = JsonConvert.DeserializeObject>(jsonString);
            string subTotal = total;
            return "success";
        }

        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public static List GetAllProduct()
        {
            List product = null;

            using (ManishTempEntities obj = new ManishTempEntities())
            {
                product = obj.Products
                    .OrderBy(p => p.Category.Name)
                    .Select(p => new Entity.Product
                    {
                        Id = p.Id,
                        CatId = p.CatId,
                        Name = p.Name,
                        CategoryName = p.Category.Name,
                    }).ToList();
            }

            return product;
        }

        internal class MyClass
        {
            public Guid Id { get; set; }

            public string Name { get; set; }

            private int _Qnty;

            public int Qnty
            {
                get { return _Qnty = 1; }
                set { _Qnty = value; }
            }

            public decimal Price { get; set; }

            public decimal Total { get; set; }
        }