Results 1 to 8 of 8

Thread: asp.net:save pictures from other page [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830

    asp.net:save pictures from other page [RESOLVED]

    We have an old site that we can't get into anymore and want to save the images for our new site. Yes, we can do a right-click and save as but this could take some time. We have the full url path stored in a database and can get access to that. I am just wondering if anyone knows of any asp.net code that will allow use to quickly save these.

    I originally found some code by Karl Moore that does a nice job of viewing an image as a thumbnail but also only works if file is on the server. (posting his code below)

    I guess either way would work if I can get to work.

    Thanks in advance.

    Karls code
    VB Code:
    1. <%
    2. ' Initialize objects
    3. Dim objImage, objThumbnail As System.Drawing.Image
    4. Dim strServerPath, strFilename As String
    5. Dim shtWidth, shtHeight As Short    
    6. ' Get image folder path on server - use "\" string if root
    7. strServerPath = Server.MapPath("images\")
    8. ' Retrieve name of file to resize from query string
    9. strFilename = strServerPath & Request.QueryString("filename")
    10.  
    11.  
    12. ' Retrieve file, or error.gif if not available
    13. Try
    14.     objImage = objImage.FromFile(strFilename)
    15. Catch
    16.     objImage = objImage.FromFile(strServerPath & "error.gif")
    17. End Try
    18. ' Retrieve width from query string
    19. If Request.QueryString("width") = Nothing Then
    20.     shtWidth = objImage.Width
    21. ElseIf Request.QueryString("width") < 1 Then
    22.     shtWidth = 100
    23. Else
    24.     shtWidth = Request.QueryString("width")
    25. End If
    26. ' Work out a proportionate height from width
    27. shtHeight = objImage.Height / (objImage.Width / shtWidth)
    28. ' Create thumbnail
    29. objThumbnail = objImage.GetThumbnailImage(shtWidth, _
    30.   shtHeight, Nothing, System.IntPtr.Zero)
    31. ' Send down to client
    32. Response.ContentType = "image/jpeg"
    33. objThumbnail.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
    34. ' Tidy up
    35. objImage.Dispose()
    36. objThumbnail.Dispose()
    37. %>

    To call this:
    http://www.url.com/viewthumbnail.asp....jpg&width=250
    Last edited by lleemon; Jun 18th, 2004 at 03:23 PM.

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    If you have access to the location where the pictures are stored, then you could just use the System.IO namespace, FileInfo class to get the files and copy them to another location.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830
    Yes, this is the issue. We can't get access. Some reason the site is no longer responding to emails, etc... and we are moving to a newer site.

  4. #4
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    If you don't have access to the server the files are located on, then it appears your only other option is to "Right Click...Save As.."
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830
    I did find some vb6 code (below) that may work to go to my pc then I will have to upload to new server. Why wouldn't ASP.NET have something similar?

    VB Code:
    1. Option Explicit
    2.  
    3.    
    4. Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL _
    5. As String, ByVal szFileName As String, ByVal dwReserved As Long, _
    6. ByVal lpfnCB As Long) As Long
    7.  
    8. Private Function DownloadFile(URL As String, _
    9. LocalFilename As String) As Boolean
    10.     Dim lngRetVal As Long
    11.     lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    12.     If lngRetVal = 0 Then DownloadFile = True
    13. End Function

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    .Net does... its called the WebClient class...

    you could use WebClient.DownloadFile, or WebClient.DownloadData.... you can find all the info in the help index.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830
    Thanks nemaroller.

    I basically used the MSDN code but does not work. Any suggestions?

    The error I get is:
    Compiler Error Message: BC30456: 'StartupPath' is not a member of 'System.Web.HttpApplicationState'.

    Thanks for the help.

    VB Code:
    1. <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
    2. <%@ Import Namespace="System.Net" %>
    3. <script runat="server">
    4. Sub Page_Load(Src As Object, E As EventArgs)
    5. Dim remoteUri As String = "http://vacmall.com/thumbnails/"
    6. Dim fileName As String = "hooverU6430a.jpg"
    7. Dim myStringWebResource As String = Nothing
    8. ' Create a new WebClient instance.
    9. Dim myWebClient As New WebClient()
    10. ' Concatenate the domain with the Web resource filename. Because DownloadFile
    11. 'requires a fully qualified resource name, concatenate the domain with the Web resource file name.
    12. myStringWebResource = remoteUri + fileName
    13. Console.WriteLine("Downloading File ""{0}"" from ""{1}"" ......." + ControlChars.Cr + ControlChars.Cr, fileName, myStringWebResource)
    14. ' The DownloadFile() method downloads the Web resource and saves it into the current file-system folder.
    15. myWebClient.DownloadFile(myStringWebResource, fileName)
    16. Console.WriteLine("Successfully Downloaded file ""{0}"" from ""{1}""", fileName, myStringWebResource)
    17. Console.WriteLine((ControlChars.Cr + "Downloaded file saved in the following file system folder:" + ControlChars.Cr + ControlChars.Tab + Application.StartupPath))
    18.  
    19. End Sub

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830
    Finally got it working. Had to take a few things out and seems to work as expected.

    This is the code I got working.

    VB Code:
    1. <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" debug="true" %>
    2. <%@ Import Namespace="System.Net" %>
    3. <script runat="server">
    4. Sub Page_Load(Src As Object, E As EventArgs)
    5. Dim remoteUri As String = "http://yourwebsite.com/images/"
    6. Dim fileName As String = "imagename.jpg"
    7. Dim myStringWebResource As String = Nothing
    8. ' Create a new WebClient instance.
    9. Dim myWebClient As New WebClient()
    10. ' Concatenate the domain with the Web resource filename. Because DownloadFile
    11. 'requires a fully qualified resource name, concatenate the domain with the Web resource file name.
    12. myStringWebResource = remoteUri + fileName
    13. ' The DownloadFile() method downloads the Web resource and saves it into the current file-system folder.
    14. fileName = "C:\websites\site.com\web\images\" + fileName
    15. myWebClient.DownloadFile(myStringWebResource, fileName)
    16.  
    17.  
    18. End Sub
    19. </script>
    20. <html>
    21. <head>
    22. <title>Download image</title>
    23. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    24. </head>
    25. <body>
    26.  
    27. </body>
    28. </html>

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