Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 31st, 2009, 11:15 AM
Authorized User
 
Join Date: Jul 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Image URL's not being imported to database

When I add a new photo album and pictures the images are not showing up in the new photo album page. When I checked the image URL in the database - its not importing them - I still see the null value.

I did go through the recommended steps in the website deployment chapter - adding Modify and Write/Read and Execute permissions to the 'Pics' Folder.

Here's code for Manage Photo Album

Code:
 
    Protected Sub LinqDataSource1_Inserting1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceInsertEventArgs) Handles LinqDataSource1.Inserting
        Dim myPicture As Picture = CType(e.NewObject, Picture)
        myPicture.PhotoAlbumID = Convert.ToInt32(Request.QueryString.Get("PhotoAlbumID"))
        Dim fileUpload1 As FileUpload = CType(ListView1.InsertItem.FindControl("FileUpload1"), FileUpload)
        Dim virtualFolder As String = "~/Pics/"
        Dim physicalfolder As String = Guid.NewGuid().ToString()
        Dim extension As String = System.IO.Path.GetExtension(fileUpload1.FileName)

    End Sub
    'first convert the file in the fileupload file
    'If the File upload file doesn't have anything that ends with .jpg then customer validator is false, cancel the fileupload

    Protected Sub ListView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewInsertEventArgs) Handles ListView1.ItemInserting
        Dim FileUpload1 As FileUpload = _
            CType(ListView1.InsertItem.FindControl("FileUpload1"), FileUpload)
        If Not FileUpload1.HasFile OrElse _
            Not FileUpload1.FileName.ToLower().EndsWith(".jpg") Then
            Dim CustomValidator1 As CustomValidator = _
            CType(ListView1.InsertItem.FindControl("CustomValidator1"), CustomValidator)
            CustomValidator1.IsValid = False
            e.Cancel = True
        End If

    End Sub
Heres from the markup:
Inserting Item
Code:
<asp:Image ID="ImageUrl" runat="server" ImageURL='<%#Eval("ImageURL") %>'/><br />

Insert Item Template 
 <asp:FileUpload ID="FileUpload1" runat="server" />
???
 
Old September 1st, 2009, 07:23 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi cortttt,

You're missing two important lines from the Inserting handler. Here's the full code for the method:

Code:
 
Protected Sub LinqDataSource1_Inserting(ByVal sender As Object, _
       ByVal e As System.Web.UI.WebControls.LinqDataSourceInsertEventArgs) _
       Handles LinqDataSource1.Inserting
  Dim myPicture As Picture = CType(e.NewObject, Picture)
  myPicture.PhotoAlbumId = Convert.ToInt32(Request.QueryString.Get("PhotoAlbumId"))
  Dim FileUpload1 As FileUpload = _
      CType(ListView1.InsertItem.FindControl("FileUpload1"), FileUpload)
  Dim virtualFolder As String = "~/GigPics/"
  Dim physicalFolder As String = Server.MapPath(virtualFolder)
  Dim fileName As String = Guid.NewGuid().ToString()
  Dim extension As String = System.IO.Path.GetExtension(FileUpload1.FileName)
 FileUpload1.SaveAs(System.IO.Path.Combine(physicalFolder, fileName + extension))
 myPicture.ImageUrl = virtualFolder + fileName + extension
 End Sub
Notice how in your code you're not saving the picture and not assigining the path to the ImageUrl property....

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old September 1st, 2009, 05:58 PM
Authorized User
 
Join Date: Jul 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah! Yes, missing a little something there (jeez). Thanks!
 
Old September 1st, 2009, 06:16 PM
Authorized User
 
Join Date: Jul 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm still having a problem; its actually a problem that crops up pretty frequently;FileName - in that piece of code (but not elsewhere) - is given a blue line underneath; it says 'object not declared for fileName'.

[
fileUpload1.SaveAs(System.IO.Path.Combine(physical folder, fileName + extension))
myPicture.ImageURL = virtualFolder + fileName + extension/]

It gets the fileName OK when it's a direct property of the FileUpload1

[Dim extension As String = System.IO.Path.GetExtension(fileUpload1.FileName)

and elsewhere but not in that piece of code.

????
 
Old September 1st, 2009, 07:55 PM
Authorized User
 
Join Date: Jul 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Found it - missed another line! (knocking my head on the wall).





Similar Threads
Thread Thread Starter Forum Replies Last Post
set image on <asp:Image> stored in DataBase myself.panku ASP.NET 2.0 Professional 1 August 11th, 2008 10:41 AM
imported DLL functions in MFC atmosphere Visual C++ 0 June 4th, 2006 08:30 PM
Remove the URL's from printouts crmpicco HTML Code Clinic 1 June 21st, 2005 11:31 AM
Profile Updates(Not About Picture URL's) Ben Horne Forum and Wrox.com Feedback 5 March 11th, 2004 05:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.