Friday, September 25, 2015


Word reader dll


Add a reference to the dll "word_reader.dll", and also add a using Statement as "using word_reader;" To extract text, use: TextExtractor extractor = new TextExtractor(PathToWordDocument); string text = extractor.ExtractText(); //The string 'text' is now loaded with the text from the Word Document

Reset Identity Column in SqlServer

Using Truncate Method.
 Using DBCC (database consistency checker)
--- TRUNCATE TABLE cannot be used when a foreign key references the table to be truncated where as DBCC can.

here is the Query using DBCC


DBCC CHECKIDENT('Table Name', RESEED, 0)
In Above query '0' is the reset idetity seed number,you can give any number whatever you want like 100,200 etc.
---Here is the Query Using Truncate 
truncate table TableName


REST

What is REST
REST stands for Representational State Transfer. (It is sometimes spelled "ReST".) It relies on a stateless, client-server, cacheable communications protocol -- and in virtually all cases, the HTTP protocol is used.

Joins Linq query

Inner Join
var empDetails = from emp in objEmp.Employees
                         join dept in objEmp.Depts on emp.Deptid equalsdept.DeptId
                         select new
                         {
                             emp.EmpName,
                             emp.Designation,
                             emp.Location,
                             dept.DeptName
                         };

Left Join
var empDetails = from emp in objEmp.Employees
                join dept in objEmp.Depts on emp.Deptid equals dept.DeptIdinto empdet
                         from de in empdet.DefaultIfEmpty()
                         select new
                         {
                             emp.EmpName,
                             emp.Designation,
                             emp.Location,
                             de.DeptName
                         };


Calling webmethod in Jquery

SELECT  n
FROM EMP o
WHERE (SELECT count(*) FROM EMP i WHERE i.n < o.n) < 5
[System.Web.Services.WebMethod]
    public static string Emp (int num, string  Name)
    {
        Emp ObjEmp = new Emp();
        ObjEmp.AddItem(n, N);
        return "Add";

    }


Call below jqery code to insert the employee data by calling the web method which has written on code behind window;

jQuery.ajax({
            url: 'Default.aspx/Emp',
            type: "POST",
            data: "{'n' : " + n + ",'N':" + N + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            beforeSend: function () {
                alert("Start");
            },
            success: function (data) {
                alert("a");
            },
            failure: function (msg) { alert("Sorry "); }
        });



Word reader dll


Add a reference to the dll "word_reader.dll", and also add a using Statement as "using word_reader;" To extract text, use: TextExtractor extractor = new TextExtractor(PathToWordDocument); string text = extractor.ExtractText(); //The string 'text' is now loaded with the text from the Word Document

Read from Microsoft Word Document doc

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices.ComTypes;
 
namespace Naresh
{
    class Program
    {
        static void Main(string[] args)
        {
            Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
            object miss = System.Reflection.Missing.Value;
            object path = @"C:\naresh\testing.docx";
            object readOnly = true;
            Microsoft.Office.Interop.Word.Document docs = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
            string totaltext = "";
            for (int i = 0; i < docs.Paragraphs.Count; i++)
            {
                   totaltext += " \r\n "+ docs.Paragraphs[i+1].Range.Text.ToString();
            }
            Console.WriteLine(totaltext);
            docs.Close();
            word.Quit();
        }
    }
}

Read from Microsoft PowerPoint file ppt

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Core;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;

namespace Naresh
{
    class Program
    {
        static void Main(string[] args)
        {
            Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = new Microsoft.Office.Interop.PowerPoint.Application();
            Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations;
            Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(@"C:\naresh\testing.pptx");
            string presentation_text = "";
            for (int i = 0; i < presentation.Slides.Count; i++)
            {
                foreach (var item in presentation.Slides[i+1].Shapes)
                {
                    var shape = (PowerPoint.Shape)item;
                    if (shape.HasTextFrame == MsoTriState.msoTrue)
                    {
                        if (shape.TextFrame.HasText == MsoTriState.msoTrue)
                        {
                            var textRange = shape.TextFrame.TextRange;
                            var text = textRange.Text;
                            presentation_text += text+" ";
                        }
                    }
                }
            }
            PowerPoint_App.Quit();
            Console.WriteLine(presentation_text);
        }
    }
}