|
-
Jun 9th, 2004, 02:51 PM
#1
Thread Starter
Fanatic Member
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:
<%
' Initialize objects
Dim objImage, objThumbnail As System.Drawing.Image
Dim strServerPath, strFilename As String
Dim shtWidth, shtHeight As Short
' Get image folder path on server - use "\" string if root
strServerPath = Server.MapPath("images\")
' Retrieve name of file to resize from query string
strFilename = strServerPath & Request.QueryString("filename")
' Retrieve file, or error.gif if not available
Try
objImage = objImage.FromFile(strFilename)
Catch
objImage = objImage.FromFile(strServerPath & "error.gif")
End Try
' Retrieve width from query string
If Request.QueryString("width") = Nothing Then
shtWidth = objImage.Width
ElseIf Request.QueryString("width") < 1 Then
shtWidth = 100
Else
shtWidth = Request.QueryString("width")
End If
' Work out a proportionate height from width
shtHeight = objImage.Height / (objImage.Width / shtWidth)
' Create thumbnail
objThumbnail = objImage.GetThumbnailImage(shtWidth, _
shtHeight, Nothing, System.IntPtr.Zero)
' Send down to client
Response.ContentType = "image/jpeg"
objThumbnail.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
' Tidy up
objImage.Dispose()
objThumbnail.Dispose()
%>
To call this:
http://www.url.com/viewthumbnail.asp....jpg&width=250
Last edited by lleemon; Jun 18th, 2004 at 03:23 PM.
-
Jun 9th, 2004, 02:55 PM
#2
Frenzied Member
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
-
Jun 9th, 2004, 04:14 PM
#3
Thread Starter
Fanatic Member
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.
-
Jun 9th, 2004, 04:23 PM
#4
Frenzied Member
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
-
Jun 9th, 2004, 04:57 PM
#5
Thread Starter
Fanatic Member
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:
Option Explicit
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL _
As String, ByVal szFileName As String, ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Function DownloadFile(URL As String, _
LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
-
Jun 17th, 2004, 09:29 AM
#6
I wonder how many charact
.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.
-
Jun 17th, 2004, 10:41 AM
#7
Thread Starter
Fanatic Member
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:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ Import Namespace="System.Net" %>
<script runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
Dim remoteUri As String = "http://vacmall.com/thumbnails/"
Dim fileName As String = "hooverU6430a.jpg"
Dim myStringWebResource As String = Nothing
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
' Concatenate the domain with the Web resource filename. Because DownloadFile
'requires a fully qualified resource name, concatenate the domain with the Web resource file name.
myStringWebResource = remoteUri + fileName
Console.WriteLine("Downloading File ""{0}"" from ""{1}"" ......." + ControlChars.Cr + ControlChars.Cr, fileName, myStringWebResource)
' The DownloadFile() method downloads the Web resource and saves it into the current file-system folder.
myWebClient.DownloadFile(myStringWebResource, fileName)
Console.WriteLine("Successfully Downloaded file ""{0}"" from ""{1}""", fileName, myStringWebResource)
Console.WriteLine((ControlChars.Cr + "Downloaded file saved in the following file system folder:" + ControlChars.Cr + ControlChars.Tab + Application.StartupPath))
End Sub
-
Jun 18th, 2004, 03:22 PM
#8
Thread Starter
Fanatic Member
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:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" debug="true" %>
<%@ Import Namespace="System.Net" %>
<script runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
Dim remoteUri As String = "http://yourwebsite.com/images/"
Dim fileName As String = "imagename.jpg"
Dim myStringWebResource As String = Nothing
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
' Concatenate the domain with the Web resource filename. Because DownloadFile
'requires a fully qualified resource name, concatenate the domain with the Web resource file name.
myStringWebResource = remoteUri + fileName
' The DownloadFile() method downloads the Web resource and saves it into the current file-system folder.
fileName = "C:\websites\site.com\web\images\" + fileName
myWebClient.DownloadFile(myStringWebResource, fileName)
End Sub
</script>
<html>
<head>
<title>Download image</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
</body>
</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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|