By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,795 Members | 1,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,795 IT Pros & Developers. It's quick & easy.

writing image to disk

P: n/a
Hey all,
I'm hoping someone can help me with a little problem I have.
First a little background. I'm working on developing a site which
displays live feeds from a security camera. The camera is connected to
our network via a network video server. Now here's the problem.
One of the requirements of this particular project is that the user be
able to save a snapshot of the live video feed at any given time and
save it to disk. Now, the network video server provides a method for
generating snapshots. The problem I have is getting the page to save
the snapshot automatically.

The address of the image actually works out to be something like
"http://www.site.com:97/images1sif?random=4325623"

The port is specified in the address because that is how the network
camera server is referenced by our routers.

I currently have a page set up that can display an image specified and
has a save button that the user can click to save the image (some of
our users aren't bright enough to right click and choose save as...).
The code I currently have is as follows:

sFileName = "Temp.jpg"
sFile = imgArchive.ImageUrl
Response.ClearHeaders()
Response.ClearContent()
Response.Clear()
Response.AddHeader("Content-Disposition","attachment;filename=" &
sFileName)
Response.ContentType = "Image/JPG"
Response.WriteFile(Server.MapPath(sFile))

This code works fine when the image is stored on the server itself,
however the images I need to save are not stored on the server, they
are on the network video server as I stated before.

Also, I will need to occasionally save these images directly to our
server for other purposes.

Any help that can be provided is appreciated. If any other
clarification is needed, please let me know.

Nov 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
First you need to retrieve the image file from the video server before you
can use Response.Writefile (or a similar function) or save it to the server.
This can be done in .NET 1.x with the WebRequest object.
Here's more info on the WebRequest object.
http://msdn.microsoft.com/library/de...classtopic.asp

In VB2005 its even easier. It can be done with a single line of code:
My.Computer.Network.DownloadFile(address as string, destinationFileName as
string)

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

<aa************@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hey all,
I'm hoping someone can help me with a little problem I have.
First a little background. I'm working on developing a site which
displays live feeds from a security camera. The camera is connected to
our network via a network video server. Now here's the problem.
One of the requirements of this particular project is that the user be
able to save a snapshot of the live video feed at any given time and
save it to disk. Now, the network video server provides a method for
generating snapshots. The problem I have is getting the page to save
the snapshot automatically.

The address of the image actually works out to be something like
"http://www.site.com:97/images1sif?random=4325623"

The port is specified in the address because that is how the network
camera server is referenced by our routers.

I currently have a page set up that can display an image specified and
has a save button that the user can click to save the image (some of
our users aren't bright enough to right click and choose save as...).
The code I currently have is as follows:

sFileName = "Temp.jpg"
sFile = imgArchive.ImageUrl
Response.ClearHeaders()
Response.ClearContent()
Response.Clear()
Response.AddHeader("Content-Disposition","attachment;filename=" &
sFileName)
Response.ContentType = "Image/JPG"
Response.WriteFile(Server.MapPath(sFile))

This code works fine when the image is stored on the server itself,
however the images I need to save are not stored on the server, they
are on the network video server as I stated before.

Also, I will need to occasionally save these images directly to our
server for other purposes.

Any help that can be provided is appreciated. If any other
clarification is needed, please let me know.

Nov 19 '05 #2

P: n/a
Thank you very much Steve. I will try this first thing in the morning
when I get back to the office.

Steve C. Orr [MVP, MCSD] wrote:
First you need to retrieve the image file from the video server before you
can use Response.Writefile (or a similar function) or save it to the server.
This can be done in .NET 1.x with the WebRequest object.
Here's more info on the WebRequest object.
http://msdn.microsoft.com/library/de...classtopic.asp

In VB2005 its even easier. It can be done with a single line of code:
My.Computer.Network.DownloadFile(address as string, destinationFileName as
string)

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


Nov 19 '05 #3

P: n/a
Steve,
Thanks again for the quick response. I do have a further question
though, and please bear in mind that I am brand new to asp.net.
While searching for solutions based off your suggestion, I came upon
the following code:
Sub Page_Load(Sender As Object, E As EventArgs)
Dim sURL As String = "http://www.site.com:82/images1sif?random=12345
Dim SR2 = New
StreamReader(System.Net.WebRequest.Create(sURL).Ge tResponse().GetResponseStream(),System.Text.Encodi ng.Unicode,True,1000000)
System.Drawing.Image.FromStream(SR2.BaseStream).Sa ve(Server.MapPath("../../Output/testing.gif"),System.Drawing.Imaging.ImageFormat.G IF)
End Sub

Now, this code works perfectly fine if the image is in a directory on
our server (i.e. www.site.com/images/image.jpg) but it fails when I try
and specify our video server which is referenced by going to port 82.

When I try and do this I get the error "The underlying connection was
closed: Unable to connect to the remote server."

Is this a problem relating to the fact that I'm specifying a port
number? Or could it possibly be that the video server just isn't
responding to the request? Keep in mind that if I just go to
www.site.com:82?/images1sif?random=12345 the image comes up perfectly
fine.

Is there another way to go about what I'm trying to do? Possibly load
the image into a standard html <img> tag and then somehow save the
contents to disk?
Again, I'm new to asp.net so please forgive me if I'm missing something
obvious.

Thanks again
Aaron Douglas

Nov 19 '05 #4

P: n/a
By default the ASPNET user account does not have access to network
directories. Either grant it access or have ASP.NET run under a different
user account by using impersonation.

For example, you can add a line similar to this to your web.config file:
<identity impersonate="true" userName="domain\MyAppUser">
password="password"/>

For testing purposes you can have it use your user account since you know
you have the necessary permissions to write to that network location.

Here's more info on impersonation:
http://msdn.microsoft.com/library/de...ersonation.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
<aa************@hotmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Steve,
Thanks again for the quick response. I do have a further question
though, and please bear in mind that I am brand new to asp.net.
While searching for solutions based off your suggestion, I came upon
the following code:
Sub Page_Load(Sender As Object, E As EventArgs)
Dim sURL As String = "http://www.site.com:82/images1sif?random=12345
Dim SR2 = New
StreamReader(System.Net.WebRequest.Create(sURL).Ge tResponse().GetResponseStream(),System.Text.Encodi ng.Unicode,True,1000000)
System.Drawing.Image.FromStream(SR2.BaseStream).Sa ve(Server.MapPath("../../Output/testing.gif"),System.Drawing.Imaging.ImageFormat.G IF)
End Sub

Now, this code works perfectly fine if the image is in a directory on
our server (i.e. www.site.com/images/image.jpg) but it fails when I try
and specify our video server which is referenced by going to port 82.

When I try and do this I get the error "The underlying connection was
closed: Unable to connect to the remote server."

Is this a problem relating to the fact that I'm specifying a port
number? Or could it possibly be that the video server just isn't
responding to the request? Keep in mind that if I just go to
www.site.com:82?/images1sif?random=12345 the image comes up perfectly
fine.

Is there another way to go about what I'm trying to do? Possibly load
the image into a standard html <img> tag and then somehow save the
contents to disk?
Again, I'm new to asp.net so please forgive me if I'm missing something
obvious.

Thanks again
Aaron Douglas

Nov 19 '05 #5

P: n/a
I'm sorry, there's one thing I didn't necessarily make clear. The
network video server in this case is not actually another computer. It
is simply a stand alone device that is connected to the network, and
the security camera at the same time. This is a box that has very
limited capabilities. The only software it really has running on it is
a basic web server (I'm not even sure what kind) and whatever software
is needed to control the camera. There are no logins, or users to
really speak of.

Is there possibly another way to do this? As I stated, loading the
image into a image control works perfectly fine. Is there any way to
possibly user the system.drawing namespace to somehow save the image?

Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.