saving-html-5-canvas-as-image-on-the-server-using-aspnet
Default.aspx.cs
PowerShell
using System;
using System.IO;
using System.Web.Script.Services;
using System.Web.Services;
[ScriptService]
public partial class _Default : System.Web.UI.Page
{
static string path = @"F:\Dinesh\";
[WebMethod()]
C#
public static void UploadImage(string imageData)
{
string fileNameWitPath = path + DateTime.Now.ToString().Replace("/", "-").Replace(" ", "- ").Replace(":", "") + ".png";
using (FileStream fs = new FileStream(fileNameWitPath, FileMode.Create))
{
using (BinaryWriter bw = new BinaryWriter(fs))
{
byte[] data = Convert.FromBase64String(imageData);
bw.Write(data);
bw.Close();
}
}
}
}Now, drawShapes() is working and I can see the graphics in canvas when view in browser. But when I click the button to save that canvas image in folder nothing is happen. How can I save that canvas image in my folder?
Dinesh Ambaliya37 pointsPosted Oct 19, 2012, 2:45 AM EDT
$.ajax({
type: 'POST',
url: 'CanvasSave.aspx/UploadImage', //correction:- url: 'Default.aspx/UploadImage'.
data: '{ "imageData" : "' + image + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',