locked
file not exists RRS feed

  • Question

  • User-333861940 posted
    
     Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
    
            'Read in the image filename to create a thumbnail of
            Dim imageUrl As String = Request.QueryString("id")
    
    
            'Make sure that the image URL doesn't contain any /'s or \'s
            If imageUrl.IndexOf("/") >= 0 Or imageUrl.IndexOf("\") >= 0 Then
                'We found a / or \
                Response.End()
            End If
    
            'Add on the appropriate directory
            imageUrl = "~/images/" & imageUrl & ".jpg"
    
            If (File.Exists(imageUrl)) Then
    
                'Get the image.    
                Dim fullSizeImg As System.Drawing.Image
                fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath(imageUrl))
    
                'Set the ContentType to "image/gif" and output the image's data
                Response.ContentType = "image/jpg"
                fullSizeImg.Save(Response.OutputStream, ImageFormat.Gif)
    
                'Dispose/clean up...
                fullSizeImg.Dispose()
            Else
                MsgBox("file does not exist")
                Response.Redirect("ShowAssessment.aspx")
            End If
        End Sub
    
    hello sir..plz help me..actually m checking whether file exists or not ..
    and if not exists it will display file does not exists..
    this msg is even displayed if the file is actually present ..
    
    plz help me why it always going for else option..
    where m i wrong???????i need it urgent
    
    Saturday, August 23, 2008 12:55 PM

Answers

  • User-417784260 posted

     

    User server.map to get the path to the file on the harddrive

     

    imageUrl = Server.Map("~/images/" & imageUrl & ".jpg")

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 23, 2008 1:06 PM
  • User-333861940 posted
    sir i did wht u told me to do..
    bt getting this error now..
    
    'C:\Documents and Settings\darpan\My Documents\Visual Studio 2005\AgraNagarNigamProject\images\30.jpg' is not a valid virtual path.
    
    
    
    plz suugest now wht to do?
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 24, 2008 12:21 AM
  • User-417784260 posted

    I am sorry.  I should have to told you to do it like this

     

            imageUrl = "~/images/" & imageUrl & ".jpg"

            If (File.Exists(Server.MapPath(imageUrl))) Then

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 24, 2008 6:29 AM

All replies

  • User-417784260 posted

     

    User server.map to get the path to the file on the harddrive

     

    imageUrl = Server.Map("~/images/" & imageUrl & ".jpg")

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 23, 2008 1:06 PM
  • User-333861940 posted
    sir i did wht u told me to do..
    bt getting this error now..
    
    'C:\Documents and Settings\darpan\My Documents\Visual Studio 2005\AgraNagarNigamProject\images\30.jpg' is not a valid virtual path.
    
    
    
    plz suugest now wht to do?
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 24, 2008 12:21 AM
  • User-417784260 posted

    I am sorry.  I should have to told you to do it like this

     

            imageUrl = "~/images/" & imageUrl & ".jpg"

            If (File.Exists(Server.MapPath(imageUrl))) Then

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 24, 2008 6:29 AM