locked
Inserting Image Path to SQL Database in Listview RRS feed

  • Question

  • User1356352994 posted

    This works as far as, getting the actual file name an storing it to the database.  But I need this to store the physical path and filename

            <InsertItemTemplate>
                <tr style="">
                    <td>
                        <asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
                            Text="Insert" />
                        <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                            Text="Clear" />
                    </td>
                    <td>
                        <asp:FileUpload ID="FileUpload1" FileName='<%# Bind("thumb") %>' runat="server" />
                    </td>
                </tr>
            </InsertItemTemplate>

    This currently saves

    myimage.jpg

    I need this to save the reference path AND filename

    images\thumbs\myimage.jpg





    Sunday, December 9, 2012 11:13 AM

Answers

  • User-1716253493 posted

    Simply modify your insert/update command

    UPDATE YOURTABLE SET FILEPATH = 'images\thumbs\' + @FILENAME

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 10, 2012 8:33 AM
  • User1356352994 posted

    I once had this as a repeater control, I changed it to a listview control.  The database solution work thanks oned. I didn't know I could do that.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 10, 2012 8:40 AM

All replies

  • User-1716253493 posted

    Try using iteminserting event to change filename value, this VB sample code

    e.Values("tumb") = "images/thumbs/" & e.Values("tumb")


    Dont save physical path if you want use the field as URL because URL and physical path is defernt

    Sunday, December 9, 2012 8:46 PM
  • User3866881 posted

    But I need this to store the physical path and filename

    We don't suggest you doing that.

    Because if you save the physical path, maybe it's an absolute one, which isn't useful for publishing futher.

    So virtual path is recommanded.

    Monday, December 10, 2012 12:25 AM
  • User1356352994 posted

    Ok so none of these solutions work and there are others telling me not to do this. 

    This is all local, Not actually uploading images. The images are already there in the folder.  I just need to store the image paths to the database using the FileUpload control.  But the FileUpload control only shows the file name xxxxx.jpg  I need it to store xxx\xxxx\xxxx.jpg on save.

    Monday, December 10, 2012 8:28 AM
  • User-1716253493 posted

    Simply modify your insert/update command

    UPDATE YOURTABLE SET FILEPATH = 'images\thumbs\' + @FILENAME

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 10, 2012 8:33 AM
  • User1356352994 posted

    I once had this as a repeater control, I changed it to a listview control.  The database solution work thanks oned. I didn't know I could do that.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 10, 2012 8:40 AM