ASP.NET MVC 및 SQL Server 2016 사용. SQL Server에 이진 데이터로 저장된 첨부 파일이 있습니다. 나는 HTML 페이지에서 하이퍼 링크로,이 첨부 파일 (이름)의 목록을 표시 할 필요가ASP.NET MVC 이진 데이터의 첨부 파일 목록
attachment_ID | attachment_GUID | attachment_data | attachment_name|
--------------|------------------|-----------------|----------------|
211 | A893C2Z1-4C0 | 0x255044462... | file1.doc |
212 | A893C2R5-4F0 | 0x255044455... | file5.pdf |
: 같은 데이터
표 보인다. 첨부 파일 이름을 클릭하면 다운로드 프로세스가 시작됩니다.
ASP.NET MVC 컨트롤러에 대한 도움이 필요합니다.
내가 파일을 직접 다운로드 컨트롤러가 :
using System;
using System.Data.SqlClient;
using System.IO;
using System.Web;
using System.Web.Mvc;
using System.Collections.Generic;
namespace Project.SERVER.Controllers
{
public class AttachmenttoHTMLController : Controller
{
#region View attachments
[HttpGet]
public ActionResult Get()
{
SqlConnection connection = Project.SERVER.Classes.INT_DataBase.getConnection();
SqlCommand command = new SqlCommand("SELECT * FROM AllAttachments WHERE document_GUID='F3A2AC32-D98D'", connection);
command.Dispose();
SqlDataAdapter sqlDtAdptr = new SqlDataAdapter(command);
System.Data.DataTable result = new System.Data.DataTable();
result.Dispose();
sqlDtAdptr.Fill(result);
sqlDtAdptr.Dispose();
connection.Dispose();
connection.Close();
if (result.Rows.Count > 0 && !System.Convert.IsDBNull(result.Rows[0]["attachment_data"]))
{
byte[] file = (byte[])result.Rows[0]["attachment_data"];
Response.ContentType = result.Rows[0]["attachment_contentType"].ToString();
return File(file, Response.ContentType, result.Rows[0]["attachment_fileName"].ToString());
}
else return new EmptyResult();
}
#endregion
}
}
내가 클릭하면 다운로드 할 수있는 옵션이 첨부 파일 목록에 대한 컨트롤러를 달성하기 위해 코드에 추가해야합니까
?
'Capture.PNG'가 프로젝트 디렉토리의'Image' 폴더 안에 있다고 가정하십시오. –
DB에서 많은 파일이 있다면 html로 루프를 사용하여 추가하여 각 파일마다 링크를 만들 수 있습니다. –
알아 내고 재현하는 데 시간이 걸렸습니다. 이 솔루션이 작동합니다. 도움을 요청 해주십시오! – Dmitry