Results 1 to 3 of 3

Thread: Image is not displayed to take a path from web.config file

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up Image is not displayed to take a path from web.config file

    Hi,

    I am using Asp.Net 3.5 application. I need to show the images when upload the file. So i saved the file in the application path and show it in the web browser. But when i publish the file the path is mismatched. Because i am using server.mappath. When publish the folder it is in different path. So i am using web.config now to put the path, and take a path from "AppSettings.ConfigurationManager". It take correct path and save it. But i load this file path to imgImage.ImageURL = filepath, it doesnt show or displaying in the browser. What is the problem here?

    When using server map path it working fine. But if i take a path from web.config file it is not displaying. I wasted one day for this one. Help me experts. I am awaiting for your response.

    Regards
    Guvera
    Failing to plan is Planning to fail

  2. #2
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: Image is not displayed to take a path from web.config file

    You should not use your web.config file to store these file paths. Web.config as it's name suggests is for your web applications configeration settings not storing data.

    That however is not the problem. If all uploaded images are stored in the same folder then you know the location so you only need to store the image name.

    If the images where in a folder called photos that was in the website root directory the url would be.

    <img src='/photos/imagename' />

    You can bind all images in a folder to a grid like this (note the path is /photos/ in code and grid imagefield)

    Code:
            Dim dr As New DirectoryInfo(Server.MapPath("/photos/"))
            gridView1.DataSource = dr.GetFiles
            gridView1.DataBind()
    Code:
    <asp:GridView ID="GridView1" runat="server" EnableModelValidation="True">
                <Columns>
                    <asp:ImageField DataImageUrlField="name" ControlStyle-Width="100" DataImageUrlFormatString="/photos/{0}">
                    </asp:ImageField>
                </Columns>
            </asp:GridView>
    Last edited by brin351; May 6th, 2011 at 05:58 AM.
    The problem with computers is their nature is pure logic. Just once I'd like my computer to do something deluded.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Image is not displayed to take a path from web.config file

    you should be using paths that are relative to the page... do NOT use Server.MapPath ... that gives you a path like "C:\wwwroot\inetpub\html\website\....." which no browser will be able to display. Which is why it's not working for you.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width