locked
Broken images after publishing website RRS feed

  • Question

  • User-712362118 posted

    I am using VWD 2010 Express and I have a webpage project built and it previews fine using the "View in Browser" button, but when I publish the site all the images break.  I must warn you, I just started using VWD, vb, etc. about a month ago.  IOW, I'm still learning things.

    The issue is with the path.  I just don't know the best/proper way to fix it.

    I am using VWD on my desktop and publishing it to a local domain server.  When I preview the page in VWD, the URL is localhost:port/images/filename.png.  After publishing, it was getting server:port/QC/images/filename.png.  The path should actually be server:port/QC/ScrapView/images/filename.png, as this is where VWD is publishing the images to.  I had to change my code behind to add the "/ScrapView" subfolder so it points to the correct place on the server for the images. (see below)

    Here is my code behind for getting the image (it's dependent on a value):

        Public Shared Function GetImage(ByVal value As Integer) As String
            If (value = 1) Then
                Return "../ScrapView/Images/chkbox_s.png"
            Else
                Return "../ScrapView/Images/chkbox_s2.png"
            End If
        End Function

    I WAS using

        Public Shared Function GetImage(ByVal value As Integer) As String
            If (value = 1) Then
                Return "../Images/chkbox_s.png"
            Else
                Return "../Images/chkbox_s2.png"
            End If
        End Function

    because it worked for the local use (preview).  But alas, I need it to work on the server, so I used the first code snippet.  But really, it should be working BOTH locally and on the server.  It would be annoying to have to publish the site to see how each change I make affects the page.  Especially AFTER it goes live.  That would not be acceptable.

    Hopefully this is clear, but in case it is not, here is a synapsis:

    Current state: Preview of the site locally has broken images.  Publishing it to the server displays images correctly.  It has to do with the code behind and the file structure between local and server paths.  I don't know how to fix this because I assumed that publishing all the files would put them in the correct paths so that the site would work as it does locally.  I guess that's my fault for publishing to a subfolder: server:port/QC/ScrapView.  Still, I expected more seemless publishing...

    Would like: to see images in both local previews and server published sites, as is the normal process. :\

    Thanks for any insight into this.

    Gavin

    Monday, January 6, 2014 10:41 AM

Answers

  • User-760709272 posted

    Return VirtualPathUtility.ToAbsolute("~/Images/chkbox_s.png")

    Assuming "~" indicates the root of your site.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 6, 2014 12:24 PM

All replies

  • User-760709272 posted

    Return VirtualPathUtility.ToAbsolute("~/Images/chkbox_s.png")

    Assuming "~" indicates the root of your site.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 6, 2014 12:24 PM
  • User-712362118 posted

    You rock, that was exactly what I needed to change my code behind returns to!

    I thought about absolute/relative paths, but didn't pursue it because I didn't know how to do it in VB - I should have Google'd absolute/relative paths in VB.  Thanks for the quick and easy resolution!

    Monday, January 6, 2014 1:40 PM