Upload, delete and download documents using Kendo upload

0 Answers 13 Views
Upload
Babu
Top achievements
Rank 1
Iron
Iron
Iron
Babu asked on 22 Apr 2024, 07:43 PM

Hi

My req is to save the documents in database in blob format. When user submits the form, the form will be saved in database and then with saved formid as reference key uploaded documents will be saved in documents table.

When user edits submitted form, I need to display already attached forms on the page. User may delete or attach new forms in edit screen.

When user viewing the form in read only mode, user should be able to download the form. How can i achieve this? 

 

below code is working for uploading...


<div class="row col-md-12">
                    <div class="col-md-10">
                        <div class="form-group">
                            @Html.LabelFor(model => model.files, htmlAttributes: new { @class = "control-label col-md-4" })
                            <div class="col-md-8">
                                @(Html.Kendo().Upload()
                                    .Name("files")
                                    .Validation(validation => validation
                                    .AllowedExtensions(new string[] { ".pdf", ".txt", ".xlsx", ".xls", ".doc", ".docx" })
                                    .MaxFileSize(15728640)
                                    .MinFileSize(3000))
                                    .ShowFileList(true)
                                    .HtmlAttributes(new { aria_label = "files" })
                                )
                                @Html.ValidationMessageFor(model => model.files, "", new { @class = "text-danger" })
                            </div>
                        </div>
                    </div>
                </div>

 

 


viewmodel class

[Display(Name = "Upload relevant documents")]
public IEnumerable<HttpPostedFileBase> files { get; set; }








foreach (var file in vm.files)
{
       byte[] document = new byte[file.ContentLength];
       file.InputStream.Read(document, 0, file.ContentLength);

       RLADOCUMENT rd = new RLADOCUMENT
       {
           RLAFORMID = (int)entity.ID,
           DOCUMENTNAME = file.FileName,
           CONTENTTYPE = file.ContentType,
           DOCUMENTSIZE = document.Length,
           DOCUMENTDATA = document,
           CREATEDBY = Environment.UserName,
           CREATEDDATE = DateTime.Now,
           EXTENSION = Path.GetExtension(file.FileName)
       };
       _context.RLADOCUMENTS.Add(rd);
       _context.SaveChanges();
}

 

Can someone help me how to display already attached files in Edit Mode with remove and upload option and download the attached reports.

No answers yet. Maybe you can help?

Tags
Upload
Asked by
Babu
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or