Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Displaying Binary Data as pdf or doc file in aspx page.Displaying Binary Data as pdf or doc file in aspx page.
Previous
 
Next
New Post
5/19/2009 7:04 AM
 

 

 

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.

 

 

 
New Post
5/19/2009 10:28 AM
 

You can add to module aspx (Binary File handler) file and create link like [YOUR_FILE.aspx]?fileID=1

and save binary data to response.

Second option you can write HttpHandler and add it to dnn web.config

 
Previous
 
Next
HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Displaying Binary Data as pdf or doc file in aspx page.Displaying Binary Data as pdf or doc file in aspx page.


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out