Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 29th, 2010, 10:58 PM
Registered User
 
Join Date: Nov 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter14 Try it Out Page 515

After I create a new photo album and upload a pictuture, the picture doesn't display in the browser on the "Manage Photo Album" page. In IE, I get the red "X" error and in FireFox just an empy space is displayed. Am I missing something in the code or is it a system issue.

I believe the pictures are uploadig because I can see and view them from the GigPics folder with the new GUID after the insert process.

Latest information:

I get the same behavior when I run the Chapter 14 website from the downloaded source code. Also, "Display Pictures" is checked under Tools-->Internet Options--> Advanced in IE.

Last edited by tostermann; November 29th, 2010 at 11:14 PM..
Reply With Quote
  #2 (permalink)  
Old November 30th, 2010, 04:00 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

>> get the same behavior when I run the Chapter 14 website

That could be correct for some albums, as the images are first created as simple text box controls. Only later are the files actually uploaded.

Can you show the markup of the page where you set up the ImageUrl and the Code Behind for the page? Also, what do you see when you look in the PhotoAlbum and Picture tables?

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!
Reply With Quote
  #3 (permalink)  
Old November 30th, 2010, 02:27 PM
Registered User
 
Join Date: Nov 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is my mark for the Markup for the "ManagePhotoAlbum" page:

Code:
<%@ Page Title="Manage Photo Album" Language="C#" MasterPageFile="~/Site/MasterPages/Frontend.master" AutoEventWireup="true" CodeFile="ManagePhotoAlbum.aspx.cs" Inherits="_ManagePhotoAlbum" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
    <asp:ListView ID="ListView1" runat="server" DataKeyNames="Id" 
        DataSourceID="EntityDataSource1" InsertItemPosition="LastItem" 
        oniteminserting="ListView1_ItemInserting">
        <InsertItemTemplate>
            <li style="">
                 Description:
                <asp:RequiredFieldValidator ID="regDesc" ControlToValidate="DescriptionTextBox" runat="server" ErrorMessage= "Enter a description."></asp:RequiredFieldValidator>
                <asp:TextBox ID="DescriptionTextBox" runat="server" MutiLine="True"
                    Text='<%# Bind("Description") %>' />
                <br />ToolTip:
                <asp:RequiredFieldValidator ID="reqToolTip" ControlToValidate="ToolTipTextBox" runat="server" ErrorMessage= "Enter a tool tip."></asp:RequiredFieldValidator>
                <asp:TextBox ID="ToolTipTextBox" runat="server" Text='<%# Bind("ToolTip") %>' />
                <asp:FileUpload ID="FileUpload1" runat="server" />
                <br />
                <asp:CustomValidator ID="cusValImage" runat="server" ErrorMessage="Select a valid .jpg file"></asp:CustomValidator>
                <br />
                <asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
                    Text="Insert" />
                <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                    Text="Clear" CausesValidation="False"/>
            </li>
        </InsertItemTemplate>
        <ItemTemplate>
            <li style="">
                Description:
                <asp:Label ID="DescriptionLabel" runat="server" 
                    Text='<%# Eval("Description") %>' />
                <br />
                ToolTip:
                <asp:Label ID="ToolTipLabel" runat="server" Text='<%# Eval("ToolTip") %>' />
                <asp:Image ID="ImageURL" runat="server" ImageUrl='<%# Eval("ImageURL")%>' />
                <br />
                <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                    Text="Delete" CausesValidation="False" />
            </li>
        </ItemTemplate>
        <LayoutTemplate>
            <ul class="ItemContainer">
                <li runat="server" id="itemPlaceholder" />
            </ul>
         </LayoutTemplate>
    </asp:ListView>
    <asp:EntityDataSource ID="EntityDataSource1" runat="server" 
        ConnectionString="name=PlanetWroxEntities" 
        DefaultContainerName="PlanetWroxEntities" EnableDelete="True" 
        EnableFlattening="False" EnableInsert="True" EntitySetName="Pictures" 
        Where="it.PhotoAlbum.Id =@photoAlbumId" 
        oninserting="EntityDataSource1_Inserting">
        <WhereParameters>
            <asp:QueryStringParameter Name="PhotoAlbumId" QueryStringField="PhotoAlbumId" 
                Type="Int32" />
        </WhereParameters>
    </asp:EntityDataSource>
</asp:Content>
Here is my C# CodeBide for the same file:

[code]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PlanetWroxModel;

public partial class _ManagePhotoAlbum : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void EntityDataSource1_Inserting(object sender, EntityDataSourceChangingEventArgs e)
{
int photoAlbumId = Convert.ToInt32(Request.QueryString.Get("PhotoAlbu mId"));
Picture myPicture = (Picture)e.Entity;
myPicture.PhotoAlbumId = photoAlbumId;

FileUpload FileUpload1 =
(FileUpload)ListView1.InsertItem.FindControl("File Upload1");
string virtualFolder = "~/Site/GigPics";
string physicalFolder = Server.MapPath(virtualFolder);
string fileName = Guid.NewGuid().ToString();
string extention = System.IO.Path.GetExtension(FileUpload1.FileName);

FileUpload1.SaveAs(System.IO.Path.Combine(physical Folder,fileName + extention));
myPicture.ImageURL = virtualFolder + fileName + extention;
}
protected void ListView1_ItemInserting(object sender, ListViewInsertEventArgs e)
{
FileUpload FileUpload1 =
(FileUpload)ListView1.InsertItem.FindControl("File Upload1");
if (!FileUpload1.HasFile || !FileUpload1.FileName.ToLower().EndsWith(".jpg"))
{
CustomValidator cusValImage =
(CustomValidator)ListView1.InsertItem.FindControl( "cusValImage");
cusValImage.IsValid = false;
e.Cancel = true;
}

}
}

FYI, my GigPics folder is under a Site foler at the base of my website. I know this is a little differ than your setup. I setup the structure wrong at the start of the book. However, I have been able to get the other items to work with small changs to paths without any issues.

Thanks!
Reply With Quote
  #4 (permalink)  
Old November 30th, 2010, 02:50 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
FYI, my GigPics folder is under a Site foler at the base of my website.
That might explain the differnet. Can you show me the following?

1. Exact address (including http) of the ManagePhotoAlbum.aspx in the browser.

2. What do you see when you request /Site in your browser for your site's address?

3. What address do you get when you right-click the GigPics folder in the Solution Explorer and choose View in Browser?

4. When you look at the source in the browser, how are the images linked?

Finally, not sure what you mean with "at the base of my website". Can you post the physical structure of the site on disk? And did you set the Virtual Path property?

Lots of questions, but somehow something is wrong and I am trying to figure out what that is...

Cheers,

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!
Reply With Quote
  #5 (permalink)  
Old November 30th, 2010, 04:53 PM
Registered User
 
Join Date: Nov 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

1. http://localhost:3779/BegASPNET/ManagePhotoAlbum.aspx

2. Directory Listing -- /BegASPNET/Site/

--------------------------------------------------------------------------------

[To Parent Directory]

Tuesday, November 30, 2010 01:09 PM <dir> Controls
Tuesday, November 30, 2010 01:09 PM <dir> Demos
Tuesday, November 30, 2010 01:09 PM <dir> GigPics
Tuesday, November 30, 2010 01:09 PM <dir> Images
Tuesday, November 30, 2010 01:09 PM <dir> MasterPages
Tuesday, November 30, 2010 01:09 PM <dir> Scripts
Tuesday, November 30, 2010 01:09 PM <dir> Styles
Tuesday, November 30, 2010 01:09 PM <dir> WebServices


--------------------------------------------------------------------------------
Version Information: ASP.NET Development Server 10.0.0.0

3. Directory Listing -- /BegASPNET/Site/GigPics/

--------------------------------------------------------------------------------

[To Parent Directory]

Monday, November 29, 2010 08:27 PM 46,815 4f631601-a46a-443e-9eac-ac14962aacc5.jpg
Monday, November 29, 2010 08:28 PM 46,815 512f191f-ea79-49aa-a216-b6183f1098be.jpg
Monday, November 29, 2010 08:07 PM 50,170 7ed9eb16-5caa-45ef-8d74-bc2ce7f2dd5f.jpg
Monday, November 29, 2010 08:18 PM 40,109 941def79-2d93-4d9b-8f23-c7f8d692b339.jpg
Monday, November 29, 2010 08:11 PM 41,477 e69ccfba-a30e-4edf-b3f4-e6742323eec9.jpg


--------------------------------------------------------------------------------
Version Information: ASP.NET Development Server 10.0.0.0

4. Based on the results of #3, I believe so. If I click a link from the ones above,I see the picture. I can also see the path when I right-click the image placeholder on the page.


5. The site is at C:\BegASPNET
About
App_Code
App_Data
App_Themes
Management
Reviews
Site
--------
Controls
Demos
GigPics
Images
MasterPages Folders enclosed in --- in Site folder
Scripts
Styles
WebServices
------------
Default.aspx
Login.aspx
ManagePhotoAlbum.aspx
NewPhotoAlbum.aspx
Web.config
Web.sitemap

Virtual Path: /BegASPNET

I hope these responses help answer you questions. Thanks for all your help on this. I have worked on this issue for hours. I know it is something simple. Learning C# and ASP.Net has been a slow up hill climb for me over the past couple of years, after coming from a FoxPro development job for 9 years. Your book is great! Do you have one for just C#?
Reply With Quote
  #6 (permalink)  
Old November 30th, 2010, 06:04 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

A few things you can try:

1. Make sure you open C:\BegASPNET/Site in Visual Studio as the root of the site.

2. Set the Virtual Path to / as explained in an earlier chapter.

3. Use MapPath("~/GigPics") as I have in my code.

I think that should fix the problem. If not, please let me know.

Cheers,

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!
Reply With Quote
  #7 (permalink)  
Old December 1st, 2010, 11:44 PM
Registered User
 
Join Date: Nov 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I finally was able to solve my problem after stepping away for a day and looking at it with fresh eyes.

I restructured my website to be in the same layout as the book. However, that didn't help. Ater running a couple tests and looking closer at the data being inserted into the database tables, I realized that GigsPics was part of my picture names in the ImageURL.

It turns out this was because of a typo in my virtual folder string.

string virtualFolder = "~/Site/GigPics";

when changed to string virtualFolder = "~/Site/GigPics/"; in the code behind it works great.

I knew it was something simple. Thanks for your help! The book is great.
Reply With Quote
  #8 (permalink)  
Old December 2nd, 2010, 03:59 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Ah, yes, that makes perfect sense. Thanks for posting a follow up.

Cheers,

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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
can’t open the page because the server where this page is located isn’t responding m_alsobaai Forum and Wrox.com Feedback 3 July 15th, 2010 06:13 AM
Problem in Chapter14 on the first 'try it out' skiabox BOOK: Beginning ASP.NET 4 : in C# and VB 1 May 9th, 2010 01:18 PM
Chap 13 PAGE 514,515 ninjamonk BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 3 October 13th, 2006 09:07 AM
Chapter14, checkout2.php-Msql error JECovill BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 May 30th, 2006 05:10 PM
Chapter14 - P421 Zaff BOOK: Access 2003 VBA Programmer's Reference 2 December 1st, 2004 10:58 PM



All times are GMT -4. The time now is 06:40 AM.


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