469,270 Members | 1,129 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

Saving TIF Image from the Internet

I have an app that (at the moment) moves through files that are on a web
site, and deletes them, wat i want to do for the next stage, is to be able to
download each file before i delete it.

i have tried POSTin to be able to view the image, then saving it, but it
doesnt work, the problem i have is that all the files on the server have the
same name, which is
http://1.1.1.1/DH/repository/content.tif

and for me to be able to view one, i had to send the follow command (that
has a fwe ids that tell me the server which file i want)

show=&did=31374&rid=6_2_6_1_2_1&sid=17470975690599 0&WidthSize=136&useSavedParam=&dummy=

once i did this i got the followin content response

HTTP/1.1 200 OK
Server: Web-Server/3.0 GW-Repository
Content-Length: 24434
Content-Type: image/x-tiff
Set-Cookie: cookieOnOffChecker=on; path=/
Connection: close

MM

i have tried to use the
WebClient.DownloadData(http://1.1.1.1/DH/repository/content.tif)

but it simply returns an error.

Does enyone have any ideas.
Thanx in advance
Nov 17 '05 #1
5 2820
Thaynann,

What is the error that you are getting? You should be able to set the
query string using the web client as well, and get the correct response, for
you to save.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Thaynann" <Th******@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
I have an app that (at the moment) moves through files that are on a web
site, and deletes them, wat i want to do for the next stage, is to be able
to
download each file before i delete it.

i have tried POSTin to be able to view the image, then saving it, but it
doesnt work, the problem i have is that all the files on the server have
the
same name, which is
http://1.1.1.1/DH/repository/content.tif

and for me to be able to view one, i had to send the follow command (that
has a fwe ids that tell me the server which file i want)

show=&did=31374&rid=6_2_6_1_2_1&sid=17470975690599 0&WidthSize=136&useSavedParam=&dummy=

once i did this i got the followin content response

HTTP/1.1 200 OK
Server: Web-Server/3.0 GW-Repository
Content-Length: 24434
Content-Type: image/x-tiff
Set-Cookie: cookieOnOffChecker=on; path=/
Connection: close

MM

i have tried to use the
WebClient.DownloadData(http://1.1.1.1/DH/repository/content.tif)

but it simply returns an error.

Does enyone have any ideas.
Thanx in advance

Nov 17 '05 #2
There is no specific message with the exception...just says "Error has
occured in WebClient", i tried grabbing the InnerException, and the
staceTrace, but no actual message with exception, just above.

i have another idea as to how to save it, that is to create a file (probably
with a FileStream) then simply write the response bytes straight to it. im
hopin this will work. ill keep u posted

"Nicholas Paldino [.NET/C# MVP]" wrote:
Thaynann,

What is the error that you are getting? You should be able to set the
query string using the web client as well, and get the correct response, for
you to save.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Thaynann" <Th******@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
I have an app that (at the moment) moves through files that are on a web
site, and deletes them, wat i want to do for the next stage, is to be able
to
download each file before i delete it.

i have tried POSTin to be able to view the image, then saving it, but it
doesnt work, the problem i have is that all the files on the server have
the
same name, which is
http://1.1.1.1/DH/repository/content.tif

and for me to be able to view one, i had to send the follow command (that
has a fwe ids that tell me the server which file i want)

show=&did=31374&rid=6_2_6_1_2_1&sid=17470975690599 0&WidthSize=136&useSavedParam=&dummy=

once i did this i got the followin content response

HTTP/1.1 200 OK
Server: Web-Server/3.0 GW-Repository
Content-Length: 24434
Content-Type: image/x-tiff
Set-Cookie: cookieOnOffChecker=on; path=/
Connection: close

MM

i have tried to use the
WebClient.DownloadData(http://1.1.1.1/DH/repository/content.tif)

but it simply returns an error.

Does enyone have any ideas.
Thanx in advance


Nov 17 '05 #3
Nicholas,

i have managed to get the image to save, by using the following code

Stream stream = webResponse.GetResponseStream();
Stream imageFile = File.Create(@"C:\IMAGES\image.tif");
Bitmap b = new Bitmap(stream);
b.Save(imageFile, ImageFormat.Tiff);

which works fine, the only problem is that, most of the fils im tryin to
save off teh web page are multi-page Tif files, and using the code above, it
seems to be only saving the first page,

i thought maybe the content returned from the server maybe only for the
first page, but i ran the web page via IE (with Fiddler running) and the
commands are identical to wat i have to view the image and IE lets me move
through the multiple pages of the image,

Any ideas?
Thanx for your help so far.
"Nicholas Paldino [.NET/C# MVP]" wrote:
Thaynann,

What is the error that you are getting? You should be able to set the
query string using the web client as well, and get the correct response, for
you to save.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Thaynann" <Th******@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
I have an app that (at the moment) moves through files that are on a web
site, and deletes them, wat i want to do for the next stage, is to be able
to
download each file before i delete it.

i have tried POSTin to be able to view the image, then saving it, but it
doesnt work, the problem i have is that all the files on the server have
the
same name, which is
http://1.1.1.1/DH/repository/content.tif

and for me to be able to view one, i had to send the follow command (that
has a fwe ids that tell me the server which file i want)

show=&did=31374&rid=6_2_6_1_2_1&sid=17470975690599 0&WidthSize=136&useSavedParam=&dummy=

once i did this i got the followin content response

HTTP/1.1 200 OK
Server: Web-Server/3.0 GW-Repository
Content-Length: 24434
Content-Type: image/x-tiff
Set-Cookie: cookieOnOffChecker=on; path=/
Connection: close

MM

i have tried to use the
WebClient.DownloadData(http://1.1.1.1/DH/repository/content.tif)

but it simply returns an error.

Does enyone have any ideas.
Thanx in advance


Nov 17 '05 #4
Thaynann wrote:
Nicholas,

i have managed to get the image to save, by using the following code

Stream stream = webResponse.GetResponseStream();
Stream imageFile = File.Create(@"C:\IMAGES\image.tif");
Bitmap b = new Bitmap(stream);
b.Save(imageFile, ImageFormat.Tiff);


You can dump the bytes read from the response stream directly to your
destination file. This can be refactored into a neat helper method.

public void Download(string url, string fileName)
{
// Add error handling for null params and other evil
// stuff on your own ;-)
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse) request.GetResponse();

using (Stream responseStream = response.GetResponseStream())
using (FileStream fileStream =
new FileStream(fileName, FileMode.Create))
{
Copy(responseStream, fileStream);
}
}

public void Copy(Stream source, Stream target)
{
// Add error handling for null params and other evil
// stuff on your own ;-)
byte[] buffer = new byte[0x1000];
int bytes;
try
{
while ((bytes = source.Read(buffer, 0, buffer.Length)) > 0)
{
target.Write(buffer, 0, bytes);
}
}
finally
{
target.Flush();
}
}

Note that there's also Webclient.DownloadFile(), which wraps these
tasks nicey ;-)

cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 17 '05 #5
Thanx for the code, i managed to get it working, with the code u gave me, i
tried to use the webClient.DownloadFile(), but i couldnt, i didnt have diret
access to the URL of the images, as all the Images i was getting had the
exact same URL, the only way to distinguish between each image was via IDs
that the server return when i posted requests.

thanx again for ur input, the app works perfectly, it was deployed yesterday

"Joerg Jooss" wrote:
Thaynann wrote:
Nicholas,

i have managed to get the image to save, by using the following code

Stream stream = webResponse.GetResponseStream();
Stream imageFile = File.Create(@"C:\IMAGES\image.tif");
Bitmap b = new Bitmap(stream);
b.Save(imageFile, ImageFormat.Tiff);


You can dump the bytes read from the response stream directly to your
destination file. This can be refactored into a neat helper method.

public void Download(string url, string fileName)
{
// Add error handling for null params and other evil
// stuff on your own ;-)
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse) request.GetResponse();

using (Stream responseStream = response.GetResponseStream())
using (FileStream fileStream =
new FileStream(fileName, FileMode.Create))
{
Copy(responseStream, fileStream);
}
}

public void Copy(Stream source, Stream target)
{
// Add error handling for null params and other evil
// stuff on your own ;-)
byte[] buffer = new byte[0x1000];
int bytes;
try
{
while ((bytes = source.Read(buffer, 0, buffer.Length)) > 0)
{
target.Write(buffer, 0, bytes);
}
}
finally
{
target.Flush();
}
}

Note that there's also Webclient.DownloadFile(), which wraps these
tasks nicey ;-)

cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de

Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by mchl gdbt | last post: by
4 posts views Thread by Michael Kennedy [UB] | last post: by
4 posts views Thread by CodeRazor | last post: by
16 posts views Thread by Fred | last post: by
5 posts views Thread by TheGanjaMan | last post: by
3 posts views Thread by Nathan Sokalski | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.