 |
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 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
|
|
|
|
|

August 5th, 2011, 11:56 PM
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
loading pictures
Hello  ,
I'll try to make this brief. I'm sorry to mention this example again, I tried to get a solution from other posts on the same section but I just couldn't find one that worked for my problem.
In the exercise on ch 14, p.515, I get no error messages but my jpgs won't load in the browser, they just have a red x. At first the fileupload would not pass validation so i took the validation out, then I checked and saw that the files were not going to my GigPics folder. Also when
I open the broken pic in a new tab the source does not have .jpg in the extension. for instance: GigPics/3cf5ba8c-3463-47a1-bfa8-2f3e111a78f1. I'm thinking this is why they won't even showup in the folder.
I am using VWD 2010 and I have not configured IIS, I'm just using its built in server. (I checked and my username has write and read permissions to the GigPics folder and all others.) I have redone this section several times, I don't think I made any typos, (my eyes are practically bleeding looking for them  ). Is there any solution aside from deleting the database and starting all over again?
I appreciate any help, thanks for taking the time to hear my problem
Thanks,
Sahpe87
Last edited by shape87; August 6th, 2011 at 12:00 AM..
|
|

August 6th, 2011, 06:28 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Can you post the code for the pages that upload and display the images?
Cheers,
Imar
|
|

August 6th, 2011, 11:30 AM
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sure, here is the source and code behind for the ManagePhotoAlbum.aspx;
Source
Code:
<%@ Page Title="Manage Photo Album" Language="C#" MasterPageFile="~/MasterPages/FrontEndAtheist.master" AutoEventWireup="true" CodeFile="ManagePhotoAlbum.aspx.cs" Inherits="_ManagePhotoAlbum" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ListView ID="ListView1" runat="server" DataKeyNames="Id"
DataSourceID="EntityDataSource1" InsertItemPosition="LastItem">
<InsertItemTemplate>
<li style="">
Description:
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text='<%# Bind("Description") %>' />
<br />
ToolTip:
<asp:TextBox ID="ToolTipTextBox" runat="server" Text='<%# Bind("ToolTip") %>' />
<br />
<asp:FileUpload ID="FileUpload1" runat="server" />
<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") %>' />
<br />
<asp:Image ID="ImageUrl" runat="server" ImageUrl='<%# Eval("ImageUrl") %>' />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" CausesValidation="False"/><br />
</li>
</ItemTemplate>
<LayoutTemplate>
<ul class="ItemContainer">
<li id="itemPlaceholder" runat="server" />
</ul>
</LayoutTemplate>
</asp:ListView>
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=AtheistEntities" DefaultContainerName="AtheistEntities"
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>
<asp:Content ID="Content3" ContentPlaceHolderID="cpClientCode" Runat="Server">
</asp:Content>
Code Behind
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AtheistModel;
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("PhotoAlbumId"));
Picture myPicture = (Picture)e.Entity;
myPicture.PhotoAlbumId = photoAlbumId;
FileUpload FileUpload1 = (FileUpload)ListView1.InsertItem.FindControl("FileUpload1");
string virtualFolder = "~/AtheistWebsite/GigPics/";
string physicalFolder = Server.MapPath(virtualFolder);
string fileName = Guid.NewGuid().ToString();
string extension = System.IO.Path.GetExtension(FileUpload1.FileName);
FileUpload1.SaveAs(System.IO.Path.Combine(physicalFolder, fileName + extension));
myPicture.ImageUrl = virtualFolder + fileName + extension;
}
}
Thanks again,
shape87
|
|

August 6th, 2011, 11:52 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
As far as I can see, that looks OK, except for this:
string virtualFolder = "~/AtheistWebsite/GigPics/";
You should be mapping to a folder in the root of your site. Maybe you forgot to set the Virtual Path property on the project to / earlier in the book?
Also, check your disk and the database. What do you see there? What data gets stored in the Picture table?
Imar
|
|

August 6th, 2011, 12:23 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
One more thing: you said validation fails, so maybe you're not uploading valid JPG files with a JPG extension? Maybe they have no extension or a double extension of which Windows is hiding one? Can you open the files in an image editor correctly?
Imar
|
|

August 6th, 2011, 03:24 PM
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I did have the folder upload to ~/GigPics/ before but I saw in another example that someone changed to put their site before it. It didn't work so I am changing it back. The folder is at the root of my site. I do not see any pictures in the folder on my disk. This is how it is showing up in my database:
https://picasaweb.google.com/1062671...PL6k6Seyu3W_AE
The pictures show up just fine in windows photo viewer. I'm not sure if they are hiding any extensions or have double extensions. I also tried taking off the extension for the actual picture off altogether to see if it would load but it still would not. This is confusing  ...
Thanks for sticking with me!
|
|

August 6th, 2011, 03:46 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Can you send me a zipped copy of your site, and one or two sample JPG files you're using to test stuff out? Something is clearly wrong, but it's a bit hard to figure out what it is without seeing more. You can find my e-mail address in the front of the book.
Cheers,
Imar
|
|

August 6th, 2011, 05:05 PM
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I sent the website to you. I appreciate you taking time to look at my site! 
|
|

August 6th, 2011, 06:31 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Figured it out! You have an UpdatePanel in your main masterpage around your ContentPlaceHolder. If you remove that, things will start to work.
FileUpload controls are not supported inside UpdatePanel controls (although there are workarounds). This prevents the file from being uploaded. This in turn means you can't save it. Additionally, FileName is empty, and thus extension is empty and thus you never saw the JPG file extension appear. Checking for FileUpload1.HasFile prevents the code from running when no file is present (although you probably wouldn't have had a clue as to why there was no file  ).
Cheers,
Imar
|
|

August 6th, 2011, 08:18 PM
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Wow... I would have never figured that out any time soon! Thank you so much for helping me Imar, it does work now. Is there a more efficient way to make the pages flicker free? To be honest, I don't think the way I had it was even working, ha. I'm learning a lot from your book, (I especially like the Sonic Youth references  .)
Thanks Again,
shape87
|
|
 |
|