We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

grid column with file upload

Thread ID:

Created:

Updated:

Platform:

Replies:

128092 Jan 2,2017 04:15 AM Jan 4,2017 08:33 PM ASP.NET MVC 1
loading
Tags: Grid
Manolo
Asked On January 2, 2017 04:15 AM

Hi,

I need a column grid with this:

1 - In edit mode, the column has a file upload for select a single file
2 - In other mode, if there is a file, this column show a link with the file for download

How can I do it?

Thanks a lot

Venkatesh Ayothi Raman [Syncfusion]
Replied On January 4, 2017 08:33 PM

Hi Manolo, 
 
Thanks for contacting Syncfusion support.  
  
We have created a custom and in which we have defined three columns (Document IDDocument Name and Download). The Download column is displayed as hyperlink using column template feature of grid. While clicking the hyperlink, it will download the excel file and for adding or editing a record that we have rendered ejUploadBox to upload/edit the document. Please refer to the code example and sample,  
  
Code example::    
 
// Upload the document and saved it in a folder.  
public void saveFiles()  
        {  
            if (HttpContext.Current.Request.Files.AllKeys.Any())  
            {  
                var httpPostedFile = HttpContext.Current.Request.Files["Uploadbox"];  
  
                if (httpPostedFile != null)  
                {  
                    fileName = httpPostedFile.FileName;  
                    destination = Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data"), fileName);  
                    httpPostedFile.SaveAs(destination);  
                }  
            }  
        }  
  
// Convert the excel file into bytes and stored into a Blob column  
  
public void Post(OrderTable value)  
        {  
            string filePath = destination;  
            string filename = fileName;  
  
             
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);  
            BinaryReader br = new BinaryReader(fs);  
            Byte[] bytes = br.ReadBytes((Int32)fs.Length);  
            br.Close();  
            fs.Close();  
            var connection = ConfigurationManager.ConnectionStrings["NORTHWNDConnectionString"].ConnectionString;  
            SqlConnection sqlCon = new SqlConnection(connection);  
            SqlCommand sqlComm = new SqlCommand("INSERT INTO [dbo].[Document]([DocumentID],[DocumentName],[Download]) VALUES (@DocumentID, @DocumentName, @Download)", sqlCon);  
            sqlComm.Parameters.AddWithValue("@DocumentID", value.DocumentID);  
            sqlComm.Parameters.AddWithValue("@DocumentName", value.DocumentName);  
            sqlComm.ExecuteNonQuery();  
            sqlCon.Close();  
        }  
  
// Retrieve the excel file  
 
public void RetrieveFile()  
        {  
            string gridModel = HttpContext.Request.Params["GridModel"];  
            GridProperties gridPropert = ConvertGridObject(gridModel);  
            var connection = ConfigurationManager.ConnectionStrings["NORTHWNDConnectionString"].ConnectionString;  
            var dataTable = new DataTable();  
            using (SqlConnection cn = new SqlConnection(connection))  
            {  
                cn.Open();  
                SqlCommand cmd = new SqlCommand("SELECT * FROM Document WHERE DocumentID = '" + Record + "'", cn);  
                SqlDataAdapter da = new SqlDataAdapter(cmd);  
                da.Fill(dataTable);  
                if (dataTable != null)  
                {  
                    download(dataTable);  
                }  
            }  
  
        }  
                    / /Download the excel File  
  
        private void download(DataTable dt)  
        {  
            Byte[] bytes = (Byte[])dt.Rows[0]["Download"];  
            Response.Buffer = true;  
            Response.Charset = "";  
            Response.Cache.SetCacheability(HttpCacheability.NoCache);  
            Response.ContentType = "application/excel";  
            Response.AddHeader("Content-disposition""filename=output.xlsx");  
            Response.BinaryWrite(bytes);  
            Response.Flush();  
            Response.End();  
        }  
 
 
 
Note In the above sample, we have achieved to download the excel file only. Similarly, you can achieve this behavior for PDF and Word document too. Please refer to the below help links to download other extension files.    
  
  
Regards,  
Venkatesh Ayothiraman. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;