Hi,
I am quiet happy working with DNN and really enjoying it.
I am creating a module to Upload and Download files. The upload saves the file contents (pdf and doc files) in sql server in varbinary(max) type field. The upload part is working greatly. The problem is with Download.
I have used editMyModule.ascx to give upload funtionality. The viewMyModule.ascx displays the list of uploaded files with a link as Download.
Here I am confused with Download. I am able to bring binary data from sql server using MyModuleController and MyModuleInfo classes and methods.
I need help to display the binary data in the form it was originally in viewMyModule.ascx page or new aspx page.
I tried it with new aspx page (named as DownloadFile.aspx) using following code but it is not showing the uploaded file data.
//Code from DownloadFile.aspx
protected void Page_Load(object sender, EventArgs e)
{
Int32 ItemId = Convert.ToInt32(Request.QueryString["ItemId"]);
Int32 ModuleId = Convert.ToInt32(Request.QueryString["ModuleId"]);
try
{
MyModuleController objMyModules = new MyModuleController();
MyModuleInfo objMyModule = objMyModules.GetMyModule(ModuleId, ItemId);
Response.AddHeader("Content-Disposition", "attachment;filename=" + objMyModule.FileName);
switch (objMyModule.FileType)
{
case "doc":
case "docx":
{
Response.ContentType = "application/msword";
break;
}
case "rtf":
{
Response.ContentType = "text/rtf";
break;
}
case "txt":
{
Response.ContentType = "text/plain";
break;
}
case "pdf":
{
Response.ContentType = "application/pdf";
break;
}
default:
{
throw InvalidFileType();
}
}
Response.BinaryWrite(objMyModule.FileData);
}
catch (Exception exc)
{
//Module failed to load
Exceptions.ProcessModuleLoadException(this, exc);
}
}
Please suggest me a way to achieve this.