Results 1 to 3 of 3

Thread: displaying pictures in a datagrid. path in DB

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    displaying pictures in a datagrid. path in DB

    Hello,

    I am using a ASP.Net application that has to upload pictures and display them in a datagrid. I cannot get the pictures to display. This is what l have done so far, and not sure if l am doing this the right way. I am hopping the one of you experts can tell me how to do it in a professional way.

    I want have the path to the pictures in the database. But l am unsure where to place the folder that will have the pictures. The folder is called images.

    The path of my application is C:\Condo\CondoInformationSystem

    <asp:TemplateColumn>
    <ItemTemplate>
    <img src='<%# DataBinder.Eval(Container.DataItem, "Picture") %>' />
    </ItemTemplate>
    </asp:TemplateColumn>

    "Picture" is the name of the database field, where the path will be stored.

    I think l have to have the images in a virtual path so it could be C:\Inetpub\wwwroot\condo\condoinformationSystem\images

    The folder "images" is where the pictures are. Is this what l should have in the database field. Not sure about this, but l read somewhere you should have only the name of the picture in this field. e.g. mypicture1.jpg. My question would be, how will the program know where this picture is?

    VB Code:
    1. string fileTarget = "C:\\Inetpub\\wwwroot\\CondoInformationSystem\\image\\";
    2. fileTarget += Path.GetFileName(ctrlFilePath.PostedFile.FileName.ToString());
    3.  
    4. if (File.Exists(fileTarget))
    5. {
    6.       Response.Write("File has already been uploaded");
    7. }
    8. else
    9. {
    10.     ctrlFilePath.PostedFile.SaveAs(fileTarget);
    11. }
    12. //With this l can store the path in the database picture field, or just the name of the picture.

    What l have done so far, does not work.

    Please can you help me solve this problem,

    Many thanks in advance,

    Steve
    steve

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: displaying pictures in a datagrid. path in DB

    Storing your pictures in C:\Condo\CondoInformationSystem\images would be fine if your application path is C:\Condo\CondoInformationSystem.

    I'm guessing that the image path that you are storing in the database is the full file path e.g. C:\Inetpub\wwwroot\condo\condoinformationSystem\images\piccy1.gif

    This is where your problem could be as obviously I can't access a physical path on you computer - it needs to be converted to a web path e.g. http://localhost/condo/condoinformat...ges/piccy1.gif.

    I would recommend storing the image path as relative to the images directory i.e. If in "C:\Inetpub\wwwroot\condo\condoinformationSystem\images\piccy1.gif" then you'd store "piccy1.gif" or if in "C:\Inetpub\wwwroot\condo\condoinformationSystem\images\subfolder\piccy2.gif" then store "subfolder/piccy2.gif"

    Your DataGrid code would then be:
    Code:
    <asp:TemplateColumn>
        <ItemTemplate>
            <img src='/images/<%# DataBinder.Eval(Container.DataItem, "Picture") %>' />
        </ItemTemplate>
    </asp:TemplateColumn>
    Give me a shout if anything isn't clear or if I've misunderstood anything!

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: displaying pictures in a datagrid. path in DB

    Hello Dj4uk,

    thanks for your quick reply.

    I will give it a try and see what happens. I will reply with my results.

    Thanks,

    Steve
    steve

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