I got a new bike ioi

Very Stylish and Fast :) I love it!

Posted in Others, Photo | Tagged , | Leave a comment

To move page with POST data using Javascript or Jquery

var url = "/Product/Delete/";

//Pure Javascript
var postForm = document.createElement("form");
postForm.method = "post";
postForm.action = url;
var input = document.createElement("input");
input.setAttribute("name", "ID");
input.setAttribute("value", ID);
postForm.appendChild(input);
document.body.appendChild(postForm);
postForm.submit();
//Using Jquery
$("body").append($("
") .attr({ "action": url, "method": "post", "id" : "postForm" }) .append($(' ') .attr({ "type": "hidden", "name": "ID", "value": ID }) ) .append($(' ') .attr({ "type": "hidden", "name": "Name", "value": "Mark Song" }) ) ).find("#postForm").submit();

For the Jquery case, please replace these words. (‘/’ is not showing in the code block..)

<form> => <form/>

<input> => <input/>

Posted in JavaScript, Tech Note | Tagged | 1 Comment

Lambda Extension Example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Extensions;

/*
* Lambda Extension Example
*/
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            IEnumerable cities = new[] { "Ghest", "London", "Las Vegas", "Hyderabad" };

            IEnumerable query = cities.Filter( (item) => item.StartsWith("L"));
            //IEnumerable query = cities.Filter(StringThatStartWithL);
            //IEnumerable query = cities.Filter(delegate(string item) { return item.StartsWith("L"); });

            foreach(var city in query){
                Console.WriteLine(city);
            }

            Console.ReadKey();
        }

        //static bool StringThatStartWithL(string s)
        //{
        //    return s.StartsWith("L");
        //}
    }
}

namespace Extensions
{
    public delegate bool FilterDelegate(T item);

    public static class FilterExtensions
    {
        public static IEnumerable Filter(this IEnumerable input,
            FilterDelegate predicate)
        {
            foreach (var item in input)
            {
                if (predicate(item))
                {
                    yield return item;
                }
            }
        }
    }
}
Posted in ASP.NET, Tech Note | Tagged , | Leave a comment

Uploading File using Ajax and receiving binary data in Asp.net (C#)

In this post, I will show you how to upload a file using Ajax (Asynchronous JavaScript and XML) and receive the binary data in Asp.net C#. And it is ultra simple!

1. HTML

2. JS

function uploadfile(){
    var bannerImage = $("#bannerImage").val();

    if (bannerImage) {
            var file = document.getElementById('bannerImage').files[0];
            var formData = new FormData();
            formData.append(file.name, file);

            var xhr = new XMLHttpRequest();
            var url = "/Category/UpdateBannerImage";
            xhr.open('POST', url, true);
            xhr.onload = function (e) {
                var response = $.parseJSON(e.target.response);
                console.log(response.fileName);
            };

           xhr.send(formData);  // multipart/form-data

    }
}

(Sending Binary Data)

3. C#, Receiving binary data

public JsonResult UpdateBannerImage()
{
    HttpPostedFileBase bannerImage = Request.Files[0] as HttpPostedFileBase;
    if (bannerImage != null && bannerImage.ContentLength > 0)
    {
	var fileName = Path.GetFileName(bannerImage.FileName);
	fileName = Regex.Replace(fileName, @"\s|\$|\#\%", "");
	var path = Path.Combine(Server.MapPath("~/images/category_banners"), fileName);
	bannerImage.SaveAs(path);

	return Json(new { success = false ,error = false, message = "Image has been updated successfully", fileName = fileName });
    }
    else
    {
	return Json(new { success = true, error = "File is empty" });
    }
}
Posted in ASP.NET, JavaScript, Tech Note | Tagged , , , | 2 Comments

Astoria, New York

Posted in Photo | Tagged | Leave a comment

Halloween in 2012

Nex5 w/ 16mm 2.8

Posted in Others, Photo | Tagged | Leave a comment

IIS7, 403 – Forbidden: Access is denied. ASP.Net MVC

I developed a application and tested on local. and I published the application on server then I got this error: 403 – Forbidden: Access is denied.

Also, I tried to run on server side,

and same error occur.

It happened because it was Forms Authentication, it is managed module. but the module was not running on the server. so it gives HTTP error 403.14-Forbidden error.

I set the ‘Run All Managed Modules for All requests’ option under the Web.Config file.

then the error message is gone.

<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"></modules>
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>

IIS Modules Overview

Posted in ASP.NET, Tech Note | Tagged , , | 1 Comment

Trigger for backup and restore data before deleting

Copy data(record) into backup table before delete data.
and restore (delete from backup table) deleted data.

Working Table : note
Backup Table : note_del

CREATE TABLE `note` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`content` text NOT NULL,
`date` datetime NOT NULL,
`userId` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
KEY `userId` (`userId`)
)

CREATE TABLE `note_del` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`content` text NOT NULL,
`date` datetime NOT NULL,
`userId` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
KEY `userId` (`userId`)
)

For backup before deleting

DELIMITER $$

USE `memoboard`$$

CREATE
DEFINER=`root`@`localhost`
TRIGGER note_delete
BEFORE DELETE ON note
FOR EACH ROW
BEGIN
INSERT INTO note_del (SELECT * FROM note WHERE id = OLD.id);
END
$$

For restore (delete from note_del table, then the record will be restore into note table)

DELIMITER $$

USE `memoboard`$$

CREATE
DEFINER=`root`@`localhost`
TRIGGER note_undelete
BEFORE DELETE ON note_del
FOR EACH ROW
BEGIN
INSERT INTO note (SELECT * FROM note_del WHERE id = OLD.id);
END
$$
Posted in Database, Tech Note | Tagged , , | Leave a comment

edmx failed to find or load the registered?

I upgrade my (Advantage Database Server) data provider version, and for some reason, I had to downgrade data provider. (v.11.0 -> v.9.1)

After remove the newer data provider, I checked there is old provider still. So I add the provider to my project reference again but I got an error message,

‘edmx failed to find or load the registered…’

I checked the provider version in properties, and it was right.

Solution,

Open,

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.xml

then I found the data provider version is still indicated newer version.

<add name="Advantage Data Provider" invariant="Advantage.Data.Provider" 

description=".Net Framework Data Provider for Advantage Database Server"

type="Advantage.Data.Provider.AdsFactory, Advantage.Data.Provider,

Version=11.00.2.0, Culture=neutral, PublicKeyToken=e33137c86a38dc06" />

After changed the version with right value, the error message has been gone :)

Oh! one more thing, I had to restart Visual Studio also.

Posted in Error Note | Tagged , , | 1 Comment

To set up for Advantage Database Server(v.11) and Code First

Server : Advantage Database Server 11

Path : \ADS_DB:6262\DB\DBB.ADD (Port : 6262)

Test Access Table : WEBORDERLN (ADT Type)

Web.config


Controller, (For use, we need to make this separate to model and controller. I mention this, because someone will say about this /..\ )

public class Ads_Context : DbContext
{
    public Ads_Context(): base("name=Ads_Context")
{
}
public DbSet webOrderLns { get; set; }
}

public class HomeController : Controller
{
    //
    // GET: /Home/

    public string Index()
    {
        var context = new Ads_Context().webOrderLns.ToList();
        return "A";
    }

}
[Table( "WEBORDERLN", Schema = "::this" )]
public class WebOrderLN
{
    [Key]
    public string PK {get; set;}
    public string FK { get; set; }
    public string pickno { get; set; }
}

The key point is,

[Table( "WEBORDERLN", Schema = "::this" )]

Advantage .NET Data Provider 11 for window download

Posted in ASP.NET, Database | Tagged , , , , | Leave a comment