Hi alpcan,
Use the following code to save the Text file. First convert the string value to ByteArray and then save the ByteArray as file using the WriteAllBytes method.
[HttpPost]
public ContentResult SaveCapture(string data)
{
if (System.IO.Directory.Exists(Server.MapPath("~/Captures")))
{
System.IO.Directory.CreateDirectory(Server.MapPath("~/Captures"));
}
string fileNametest = DateTime.Now.ToString("dd-MM-yy hh-mm-ss");
byte[] datats = System.Text.Encoding.ASCII.GetBytes(data);
string filePathtest = Server.MapPath(string.Format("~/Captures/{0}.txt", fileNametest));
System.IO.File.WriteAllBytes(filePathtest, datats);
return Content("true");
}
JavaScript
$("#btnUpload").click(function () {
$.ajax({
type: "POST",
url: "/Home/SaveCapture",
data: "{data: '" + "deneme test" + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) { }
});
});
But why are you saving the text data as file, while capturing the image from webcam?