Upload File along with Data in Sql DB in MVC [Resolved]

Posted by Suryagniit under ASP.NET MVC on 12/23/2015 | Points: 10 | Views : 622 | Status : [Member] | Replies : 2
Hello,

I want to store any kind of file along with some extra column data in sql server db using mvc 4/5.

Please help me out.

Thanks.

Surya Prakash Pandey.


Responses

Posted by: Sheonarayan on: 12/23/2015 [Administrator] HonoraryPlatinum | Points: 50

Up
1
Down

Resolved
Read this post that will help you http://techfunda.com/howto/281/file-upload.

In above post, only "Active" column is extra, you can add your column like "Gender", "Email", "Qualification" etc.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Suryagniit, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 12/24/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
@Suryagniit Sir, We equally had a similar kind of requirement. Any kind of file could be uploaded (like pdf, image, image inside pdf, txt, doc, zip, etc.) . I agree that our major technologies were AngularJS, WebAPI, EF and SQL Server (among the others).

We modeled as under

public byte[] DocumentData { get; set; }


and the DB table structure was

CREATE TABLE [dbo].[tblLeadDocuments](

[LeadDocumentsId] [int] IDENTITY(1,1) NOT NULL,
[DocumentId] [int] NULL,
[DocumentData] [image] NULL,
[FileExtension] [varchar](5) NULL,
[DocumentStatusId] [int] NULL,
CONSTRAINT [PK_tblLeadDocuments] PRIMARY KEY CLUSTERED
(
[LeadDocumentsId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]


As can be figure out [DocumentData] type was [image] .

However, from the angular side we were converting the files to base64 and was passing to the byte array exposed by the WebAPI.

Also please note that [FileExtension] column was kept for storing the file extension. This comes handy at the time of converting the response satisfying the proper file identity. This was happening at the AngularJS side.


Hope this tip will be helpful along with the above mentioned responses.

Thanks.

--
Thanks & Regards,
RNA Team

Suryagniit, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response