// 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();
} |
Hi,
I am trying UploaderComponent inside the React Grid component. I am able to upload the file without any issues.
When I try to update the grid after upload, I get the below error.
TypeError: Cannot read properties of undefined (reading 'enqueueForceUpdate')
I have also created a demo link below.
https://stackblitz.com/edit/react-fhp5sa
Let me know if you need more details.
fileUploadTemp = {
//defining the cell edit template for the image column
create: () => {
this.fileUploadElem = document.createElement('input');
return this.fileUploadElem;
},
read: () => {
return this.fileUploadObj.filesData.length > 0
? this.fileUploadObj.filesData[0].name
: '';
},
destroy: () => {
this.fileUploadObj.destroy();
},
write: () => {
this.fileUploadObj = new Uploader({
id: 'postedFiles',
name: 'postedFiles',
autoUpload: false,
asyncSettings: {
saveUrl: 'https://ej2.syncfusion.com/services/api/uploadbox/Save',
removeUrl: 'https://ej2.syncfusion.com/services/api/uploadbox/Remove',
},
});
this.fileUploadObj.appendTo(this.fileUploadElem);
},
};
|