public int GetProgramSeq()
{
int i = 0;
using (PbotEntities ctx = new PbotEntities())
{
var results = ctx.SP_GET_SEQ_PROGRAM();
long? nextSequenceValue = results.SingleOrDefault();
if( int.TryParse( nextSequenceValue.Value.ToString() , out i ))
{
i = int.Parse(nextSequenceValue.Value.ToString());
}
return i;
}
}
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace WpfApp1
{
/// <summary>
/// App.xaml에 대한 상호 작용 논리
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
new MainWindow().Show();
base.OnStartup(e);
}
}
}
// When the blob is complete, make an anchor tag for it and use the tag to initiate a download
// Works in:
// * Chrome
// * IE11, Edge
// * Firefox
function myCallback(blob) {
//서버로 전송
$.ajax({
type: "POST",
url: "/api/diagramUpload/100",
data: blob,
processData: false,
contentType: false,
success: function (data) {
alert('저장성공');
},
error: function (message) {
alert(message);
}
});
return;
//여기서 부터는 파일을 웹브라우저에서 바로 다운받는다.
var url = window.URL.createObjectURL(blob);
var filename = "pbot.png";
var a = document.createElement("a");
a.style = "display: none";
a.href = url;
a.download = filename;
// IE 11
if (window.navigator.msSaveBlob !== undefined) {
window.navigator.msSaveBlob(blob, filename);
return;
}
document.body.appendChild(a);
requestAnimationFrame(function () {
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
});
}
ASP.NET API 에서 파일을 다운로드 하는방법
/// <summary> 프로젝트 파일을 저장 합니다.</summary>
/// <returns></returns>
[System.Web.Http.Route("api/diagramUpload/{projectId}")]
[System.Web.Http.HttpPost]
public Task diagramUploadAsync(int projectId)
{
string root = System.Web.HttpContext.Current.Server.MapPath("~/ProjectImages");
HttpRequestMessage request = this.Request;
var content = request.Content;
FileStream fileStream = null;
string pathname = string.Format(@"{0}\{1}.png", root, projectId);
try
{
fileStream = new FileStream(pathname, FileMode.Create, FileAccess.Write, FileShare.None);
return content.CopyToAsync(fileStream).ContinueWith(
(copyTask) =>
{
fileStream.Close();
});
}
catch
{
if (fileStream != null)
{
fileStream.Close();
}
throw;
}
}