Failed to map the path '/uploads/Lighthouse_thumb.jpg'.
Below is the code:
Public Sub imageThumbnail(ByVal photoName As String)
'Read in the image filename to create a thumbnail of
Dim imageUrl As String = photoName
'Read in the width and height
Dim imageHeight As Integer = 132
Dim imageWidth As Integer = 132
'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 = "/uploads/" & imageUrl & "_thumb.jpg"
Dim fullSizeImg As System.Drawing.Image
fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath(imageUrl))
'Do we need to create a thumbnail?
Response.ContentType = "image/gif"
If imageHeight > 0 And imageWidth > 0 Then
Dim dummyCallBack As System.Drawing.Image.GetThumbnailImageAbort
dummyCallBack = New _
System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
Dim thumbNailImg As System.Drawing.Image
thumbNailImg = fullSizeImg.GetThumbnailImage(imageWidth, imageHeight, _
dummyCallBack, IntPtr.Zero)
thumbNailImg.Save(Response.OutputStream, ImageFormat.Gif)
'Clean up / Dispose...
thumbNailImg.Dispose()
Else
fullSizeImg.Save(Response.OutputStream, ImageFormat.Gif)
End If
'Clean up / Dispose...
fullSizeImg.Dispose()
End Sub
atiqjaved
Member
20 Points
64 Posts
error while creating thumbnail
Nov 03, 2010 02:00 AM|LINK
I am getting the following error:
Failed to map the path '/uploads/Lighthouse_thumb.jpg'.
Below is the code:
Public Sub imageThumbnail(ByVal photoName As String) 'Read in the image filename to create a thumbnail of Dim imageUrl As String = photoName 'Read in the width and height Dim imageHeight As Integer = 132 Dim imageWidth As Integer = 132 '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 = "/uploads/" & imageUrl & "_thumb.jpg" Dim fullSizeImg As System.Drawing.Image fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath(imageUrl)) 'Do we need to create a thumbnail? Response.ContentType = "image/gif" If imageHeight > 0 And imageWidth > 0 Then Dim dummyCallBack As System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = New _ System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback) Dim thumbNailImg As System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(imageWidth, imageHeight, _ dummyCallBack, IntPtr.Zero) thumbNailImg.Save(Response.OutputStream, ImageFormat.Gif) 'Clean up / Dispose... thumbNailImg.Dispose() Else fullSizeImg.Save(Response.OutputStream, ImageFormat.Gif) End If 'Clean up / Dispose... fullSizeImg.Dispose() End SubAny help would be much appreciated...
Thanks
anas
All-Star
73649 Points
7914 Posts
Moderator
Re: error while creating thumbnail
Nov 06, 2010 09:02 PM|LINK
Try to prefix the path with the tilde character:
imageUrl = "~/uploads/" & imageUrl & "_thumb.jpg"
This way, you will make sure that you are always starting from the root website folder not matter from where you call the MapPath.