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...Building ExtensionsBuilding ExtensionsModulesModulesDisplay Image from Database (binary)Display Image from Database (binary)
Previous
 
Next
New Post
11/23/2010 7:07 PM
 
Hello All,

I'm hoping somebody can steer me in the right direction here. I have an existing application that I am converting to a DNN module. I have created a user control from my existing ASPX page. It works as a DNN module except for one piece, displaying images from the database.

The method I was using using another .aspx page to render the image within a DetailsView control:

<ItemTemplate>
                                        <asp:HyperLink id="hlkBikePic2" runat="server" CssClass="thumbnail" ImageUrl='<%# Eval("UserBikeID", "ShowPicture.aspx?id={0}&type=bike") %>'
                                            NavigateUrl='<%# Eval("UserBikeID", "ShowPicture.aspx?id={0}&type=bike") %>' Target="_blank" Text="No Bike Picture Uploaded"></asp:HyperLink>
                                    </ItemTemplate>

Then ShowPicture.aspx has the following in the Page_Load event (here's the important part):

If myReader.Read Then
                If Not IsDBNull(myReader("BinaryData")) Then
                    Response.ContentType = Trim(myReader("MIMEType").ToString())
                    Response.BinaryWrite(myReader("BinaryData"))
                Else
                    Response.Write("No Picture Uploaded")
                End If
            End If

How can I achieve the same results in DNN? I'm guessing that you can't just directly reference an .aspx page once in the DNN framework. So how else can I do this?

Thanks in advance,
Chad
 
New Post
11/23/2010 8:23 PM
 
Are you using DNN 5.6? If so I think there's a chance the ASPX page will work, there are some changes that appear to have broken things. Here's a thread discussing. http://www.dotnetnuke.com/Resources/F...

If you are on an older version of DNN you should still be able to do that without too much trouble. You need to provide a full path to that ASPX file though.

Chris Hammond
Former DNN Corp Employee, MVP, Core Team Member, Trustee
Christoc.com Software Solutions DotNetNuke Module Development, Upgrades and consulting.
dnnCHAT.com a chat room for DotNetNuke discussions
 
New Post
11/23/2010 9:34 PM
 
You can use an aspx file for this purpose in DotNetNuke and if you take a look at the source code for the DNN Gallery module (available at http://dnngallery.codeplex.com) you will see that being done with Image.aspx. To avoid the issue which Chris was referring to in DNN 5.06.00 you need to provide a full, not relative path to the aspx file when setting the src attribute of the <image /> tag and should include either the tabid or portalid or moduleid in the url's query string. I was pleased to see that the use of Image.aspx for image streaming in Gallery 4.03.03 is still working in DotNetNuke 5.06.00.

Rather than using an aspx file for image streaming, my own preference is to use a generic Http handler (.ashx extension) as it is a much lighter object than an aspx page for the ASP.Net runtime to create each time it is needed and particularly when used in a grid should result in better performance. An advantage of a generic Http handler (.ashx) over a custom Http handler with it's own extension is that the generic Http handler does not need to be registered in the web.config.

For an example of a generic Http handler as well as many image processing methods, you may wish to look at the source code for my DotNetNuke Extensions Forge project ImageEditorControl at http://imageeditor.codeplex.com . The generic Http handler for image streaming is found in the HttpHandlers folder and is named DynamicImage.ashx.vb. Note: This project was created in 2008 and is badly in need of updating in regards to changes in file/folder/permissions handling in DNN 5.x. My plans are to recreate it as a Silverlight 4 project with enhanced editing capabilities.

Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
11/24/2010 12:41 AM
 
I've looked at some of the things you mentioned, but as a newbie, it seems above my skills at this point. So I am going to just try to use the .aspx page and fully qualify it. 


Now the problem I am having is connecting to the database. It works when I run the UC in a Test.aspx page outside of DNN, but after installing it into DNN, I get the error related to BuildManager.GetType (i.e. same issue as this:Here). Here's what I'm doing:

Imports System.Data
Imports System.Data.SqlClient
Partial Class lib_ShowPicture
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim ID As Integer = Convert.ToInt32(Request.QueryString("ID"))
        Dim strType As String = Request.QueryString("type").ToString
        Dim strSQL As String


'Connect to the database and bring back the image contents & MIME type for the specified picture
Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString)


Select Case strType
Case Is = "bike"
strSQL = "SELECT [MIMEType], [PictureData] as BinaryData FROM [Dyno_UserBikes] WHERE [UserBikeID] = @ID"
Case Is = "dyno"
strSQL = "SELECT [MIMEType], [ChartBinary] as BinaryData FROM [Dyno_DynoRuns] WHERE [DynoRunID] = @ID"
End Select


Dim myCommand As New SqlCommand(strSQL, myConnection)
myCommand.Parameters.AddWithValue("@ID", ID)


myConnection.Open()
Dim myReader As SqlDataReader = myCommand.ExecuteReader


If myReader.Read Then
If Not IsDBNull(myReader("BinaryData")) Then
Response.ContentType = Trim(myReader("MIMEType").ToString())
Response.BinaryWrite(myReader("BinaryData"))
'Response.OutputStream.Write( myReader("PictureData"))
Else
Response.Write("No Picture Uploaded")
End If
End If


myReader.Close()
myConnection.Close()
End Using
    End Sub


End Class

Getting this error:
AssemblyVersion: 5.5.1
PortalID: -1
PortalName:
UserID: -1
UserName:
ActiveTabID: -1
ActiveTabName:
RawURL:
AbsoluteURL:
AbsoluteURLReferrer:
UserAgent:
DefaultDataProvider: DotNetNuke.Data.SqlDataProvider, DotNetNuke.SqlDataProvider
ExceptionGUID: ce21afd6-4566-403a-9929-6b96aa16ec49
InnerException: Could not load type 'Incite.Modules.Dyno_Garage.Dyno_GarageController'.
FileName:
FileLineNumber: 0
FileColumnNumber: 0
Method: System.Web.Compilation.BuildManager.GetType
StackTrace:
Message: System.Web.HttpException: Could not load type 'Incite.Modules.Dyno_Garage.Dyno_GarageController'. at System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) at DotNetNuke.Framework.Reflection.CreateType(String TypeName, String CacheKey, Boolean UseCache, Boolean IgnoreErrors)
 
New Post
11/24/2010 8:52 AM
 
The error you posted is not related to your ShowPicture.aspx code which I suspect is never getting called as the error is most likely occuring when your module's view control is being loaded. The error is related to the namespace conflicts which I discussed in your other thread. I would suggest first getting the module's view and edit controls to load properly and display some static text before working on displaying an image from database blob data.

Regarding the code you posted for ShowPicture, I would encourage you to make use of stored procedures rather than building the SQLCommnd strings as you are doing and looking into making use of DotNetNuke's data layer helpers such as DAL+ (check out Michael Washington's tutorials) rather than managing your own DataReader. If you decide to use your own code, be sure to use a try . . . catch . . . finally block to ensure that the DataReader as well as the connection gets closed in the event of an error.

Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesDisplay Image from Database (binary)Display Image from Database (binary)


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