How to access google chrome history in c# programming with sqlite

First you need to add a reference to the SQLite assembly, its very similar to standard ADO.net.

All the user history is stored in the History database located at the path in the connection string below.


using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BrowserHistory
{
class Program
{
static void Main(string[] args)
{

SQLiteConnection conn = new SQLiteConnection
(@"Data Source=C:\Users\Mahaveer Jangid\Desktop\History");
conn.Open();
SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = conn;
// cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;";
// Use the above query to get all the table names
cmd.CommandText = "Select * From urls";
SQLiteDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Console.WriteLine(dr[1].ToString());
Console.WriteLine("----------------------------------------");
}

Console.ReadLine();
}
}

}

Preview an image before it is uploaded in Jquery

How to preview image before uploading in jquery.

function readURL(input) {

  if (input.files && input.files[0]) {
    var reader = new FileReader();

    reader.onload = function(e) {
      $('#blah').attr('src', e.target.result);
    }

    reader.readAsDataURL(input.files[0]);
  }
}

$("#imgInp").change(function() {
  readURL(this);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="form1" runat="server">
  <input type='file' id="imgInp" />
  <img id="blah" src="#" alt="your image" />
</form>

Maximum request length exceeded

If you are using IIS for hosting your application, then the default upload file size if 4MB. To increase it, please use this below section in your web.config –

<configuration>
    <system.web>
        <httpRuntime maxRequestLength="1048576" />
    </system.web>
</configuration>

For IIS7 and above, you also need to add the lines below:

 <system.webServer>
   <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
   </security>
 </system.webServer>

Note:

  • maxRequestLength is measured in kilobytes
  • maxAllowedContentLength is measured in bytes

which is why the values differ in this config example. (Both are equivalent to 1 GB)

 

Program to Check Whether a String Palindrome is or not in c#

It contains a program to reverse a string and to check whether a Entered string is palindrome or not.

using System; 
namespace palindrome 
{ 
class Program 
{ 
static void Main(string[] args) 
{ 
string s,revs=""; 
Console.WriteLine(" Enter string"); 
s = Console.ReadLine(); 
for (int i = s.Length-1; i &gt;=0; i--) //String Reverse 
{ 
revs += s[i].ToString(); 
} 
if (revs == s) // Checking whether string is palindrome or not 
{ 
Console.WriteLine("String is Palindrome \n Entered String Was {0} and reverse string is {1}", s, revs); 
} 
else 
{ 
Console.WriteLine("String is not Palindrome \n Entered String Was {0} and reverse string is {1}", s, revs); 
} 
Console.ReadKey(); 
} 
} 
}

How do I import a namespace in Razor View Page?

How can i import namespaces in razor page in asp.net mvc

For namespace and Library

@using NameSpace_Name

For Model

 

@model Application_Name.Models.Model_Name 

For Iterate the list on Razor Page (You Have to use foreach loop for access the list items)

 

@model List<Application_Name.Models.Model_Name>

@foreach (var item in Model)
   {  
          <tr>
                <td>@item.srno</td>
                <td>@item.name</td>
         </tr>  
   }

Synchronize live database from local SQL Server database in C#

Synchronize live database from local SQL Server database in C#

You can search for .NET Sync Framework With this framework you can create 3 methods, 1. for server machine or Destination machine 2. for client machine or Source machine DB 3. Sync Method

Create Connection String First for client and server and scope name according to your choice.


 static string sServerConnection = @"Data Source=192.168.1.112;Initial Catalog=Server;User ID=sa;Password=123456";

    static string sClientConnection = @"Data Source=MAHAVEER;Initial Catalog=Client;Integrated Security=True";

    static string sScope = "MainScope";
Get and store the data from Client Machine

 //Get Data From Client Provision
    public static void ProvisionClient()
    {
        SqlConnection serverConn = new SqlConnection(sServerConnection);
        SqlConnection clientConn = new SqlConnection(sClientConnection);

        //Drop scope_Info Table
        string cmdText = @"IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES 
                   WHERE TABLE_NAME='scope_info') DROP table scope_info";
        clientConn.Open();
        SqlCommand cmd = new SqlCommand(cmdText, clientConn);
        cmd.ExecuteScalar();
        clientConn.Close();


        List<string> tables = new List<string>();
        tables.Add("Demo"); // Add Tables in List
        tables.Add("Product");

        var scopeDesc = new DbSyncScopeDescription("MainScope");
        foreach (var tbl in tables) //Add Tables in Scope
        {
            scopeDesc.Tables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable(tbl, clientConn));
        }

        SqlSyncScopeProvisioning clientProvision = new SqlSyncScopeProvisioning(clientConn, scopeDesc); //Provisioning

        //skip creating the user tables
        clientProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);

        //skip creating the change tracking tables
        clientProvision.SetCreateTrackingTableDefault(DbSyncCreationOption.Skip);

        //skip creating the change tracking triggers
        clientProvision.SetCreateTriggersDefault(DbSyncCreationOption.Skip);

        //skip creating the insert/update/delete/selectrow SPs including those for metadata
        clientProvision.SetCreateProceduresDefault(DbSyncCreationOption.Skip);

        //create new SelectChanges SPs for selecting changes for the new scope
        //the new SelectChanges SPs will have a guid suffix
        clientProvision.SetCreateProceduresForAdditionalScopeDefault(DbSyncCreationOption.Create);


        clientProvision.Apply();
    }
Set The data to Server machine with the help of provisioning

    //Set Data To Server Provision
    public static void ProvisionServer()
    {

        SqlConnection serverConn = new SqlConnection(sServerConnection);

        string cmdText = @"IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES 
                   WHERE TABLE_NAME='scope_info') DROP table scope_info";
        serverConn.Open();
        SqlCommand cmd = new SqlCommand(cmdText, serverConn);
        cmd.ExecuteScalar();
        serverConn.Close();

        List<string> tables = new List<string>();
        tables.Add("Demo");
        tables.Add("Product");

        var scopeDesc = new DbSyncScopeDescription("MainScope");
        foreach (var tbl in tables)
        {
            scopeDesc.Tables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable(tbl, serverConn));
        }

        SqlSyncScopeProvisioning serverProvision = new SqlSyncScopeProvisioning(serverConn, scopeDesc); // Create Provision From All Tables

        //skip creating the user tables
        serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);

        //skip creating the change tracking tables
        serverProvision.SetCreateTrackingTableDefault(DbSyncCreationOption.Skip);

        //skip creating the change tracking triggers
        serverProvision.SetCreateTriggersDefault(DbSyncCreationOption.Skip);

        //skip creating the insert/update/delete/selectrow SPs including those for metadata
        serverProvision.SetCreateProceduresDefault(DbSyncCreationOption.Skip);

        serverProvision.Apply();


    }
After above two process sync process will start according to your provisining and SyncOrchestrator Class will be responsible for all sync process it is class of Microsoft Sync Framework

 public static void Sync()

    {
        SqlConnection serverConn = new SqlConnection(sServerConnection);

        SqlConnection clientConn = new SqlConnection(sClientConnection);

        SyncOrchestrator syncOrchestrator = new SyncOrchestrator();

        syncOrchestrator.LocalProvider = new SqlSyncProvider(sScope, clientConn);

        syncOrchestrator.RemoteProvider = new SqlSyncProvider(sScope, serverConn);

        syncOrchestrator.Direction = SyncDirectionOrder.Upload;

        ((SqlSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed);

        SyncOperationStatistics syncStats = syncOrchestrator.Synchronize();

        Console.WriteLine("Start Time: " + syncStats.SyncStartTime);

        Console.WriteLine("Total Changes Uploaded: " + syncStats.UploadChangesTotal);

        //Console.WriteLine("Total Changes Downloaded: " + syncStats.DownloadChangesTotal);

        Console.WriteLine("Complete Time: " + syncStats.SyncEndTime);

        Console.WriteLine(String.Empty);

        Console.ReadLine();

    }
If any Changes or Error will occur than this method will return.

    static void Program_ApplyChangeFailed(object sender, DbApplyChangeFailedEventArgs e)

    {

        Console.WriteLine(e.Conflict.Type);

        Console.WriteLine(e.Error);

    }
And than Call the above three method in main method. make sure you have to call these methods in a proper way, like first data receive from client machine than set to server machine and than sync process will start

static void Main(string[] args)
    {
        ProvisionClient();
        ProvisionServer();
        Sync();
    }
I Hope this will Helpfull for you, i used this code in a project and this worked fine for me. this is only for single client and single machine sync process not for multiple.

Displaying C# code in WordPress website

Displaying C# code in WordPress website

Just edit your aricles in html mode and enclose your code within these tags.

[sourcecode language="csharp"]
[/sourcecode]

Example:

[sourcecode language="javascript"]
 // javascript hello world program
 alert('Hello, World !!');
[/sourcecode]

Note: You need to specify correct language identifier for the language attribute as shown above.

 

Here the List

Available language codes:

  • actionscript3
  • bash
  • clojure
  • coldfusion
  • cpp
  • csharp
  • css
  • delphi
  • erlang
  • fsharp
  • diff
  • groovy
  • html
  • javascript
  • java
  • javafx
  • matlab (keywords only)
  • objc
  • perl
  • php
  • text
  • powershell
  • python
  • r
  • ruby
  • scala
  • sql
  • vb
  • xml

Above language code you can use.