File uploading to a database was easy to implement with the help of this post
thanks aspcode.net. I am using linq to sql, so I had to modify a few things. Here is my code.
private IEnumerable<Report> cReport
{
get { return (IEnumerable<Report>)this.Session["cReport"]; }
set { this.Session["cReport"] = (IEnumerable<Report>)value; }
}
private ReportContext ctxReport
{
get { return (ReportContext)this.Session["ctxReport"]; }
set { this.Session["ctxReport"] = (ReportContext)value; }
}
protected void InsertButton_Click(object sender, EventArgs e)
{
this.Page.Validate();
if (this.Page.IsValid)
{
FileUpload fu = ((FileUpload)this.fvReport.FindControl("fuFile"));
byte[] bData = new byte[fu.PostedFile.ContentLength];
fu.PostedFile.InputStream.Read(bData, 0, fu.PostedFile.ContentLength);
//Retrieve filename
System.IO.FileInfo oInfo = new System.IO.FileInfo(fu.PostedFile.FileName);
xxx.TourAdmin.Data.Report rep = new xxx.TourAdmin.Data.Report();
rep.active = true;
rep.FileLength = fu.PostedFile.ContentLength;
rep.FileName = oInfo.Name;
rep.ReportData = bData;
this.ctxReport.Report.InsertOnSubmit(rep);
this.ctxReport.SaveAll();
}
this.gvReports.DataBind();
}
No comments:
Post a Comment