Ask a Question related to ASP.NET General, Design and Development.
-
Paul Gorman #1
Uploading an Image from a web page
I am using the control type = file to perform a file
upload. When I click on the browse button to go select
the image I want to upload it places in the text box a
local path (C:\images\image.jpg for example). This is
where the image resides that I want to upload. Then I
proceed to click on upload so that I can run through my
code to do the upload process:
string strConnection = "some connection string";
SqlConnection oCon = new SqlConnection(strConnection);
SqlCommand oCom = new SqlCommand();
oCom.CommandText = "usp_msa_image_save_binary";
oCom.CommandType = CommandType.StoredProcedure;
oCom.Connection = oCon;
oCon.Open();
FileStream fs;
string strFileName = this.loFile.PostedFile.FileName;
fs = File.OpenRead(strFileName);
int intCount = (int)fs.Length;
int intSize;
byte[] buffer = new byte[intCount];
fs.Read(buffer,0,intCount);
oCom.Parameters.Add("@Image", SqlDbType.Image).Value =
buffer;
oCom.Parameters.Add("@itemID", SqlDbType.VarChar,
30).Value = "CEH03BA401"; //Request.QueryString.Get
("name");
if ( this.chkSmallImage.Checked )
{
oCom.Parameters.Add("@size", SqlDbType.Int).Value = 1;
intSize = 1;
}
else
{
oCom.Parameters.Add("@size", SqlDbType.Int).Value = 2;
intSize = 2;
}
oCom.ExecuteNonQuery();
string strItemNumber = Request.QueryString.Get("name");
string strUrl = "image_binary_get.aspx?itemnumber=" +
strItemNumber + "&size=" + intSize;
this.imgView.ImageUrl = strUrl;
It continues to fail at
fs = File.OpenRead(strFileName);
with the error message:
"Could not find part of the path "C:\images\image.jpg".
The one thing that I can be sure of is this. When i
attempt this process on the IIS Server where all this
resides then it works great. As soon as I try to upload
a file from some other computer on the network i get that
error. Any help would be greatly appreciated. Thanks in
advance.
Paul Gorman ><>
Paul Gorman Guest
-
Don't want an /image folder when uploading images
I want to be able to upload image files from my local computer using Contribute CS3 without having the program create an IMAGES folder. I don't... -
Uploading image
I'm got a cool uploading images tutorial from Asfusion.com. I got it working but this is my issue. I created a db table called "photos", in the... -
Uploading Image to server problems
I am trying to upload an image to the server from the browser using a form and an ADODB binary stream. The file successfully saves to the correct... -
uploading imageready image map
hello, i'm pretty new to photoshop and have just made my first image map with rollovers using photoshop and imageready. when i preview it in the... -
getting image width/height before uploading
Hello, Q: How do I get image width and height before uploading an image? This because, I want to restrict people uploading huge files. ... -
Bülent Keskin #2
Re: Uploading an Image from a web page
this.loFile.PostedFile.FileName just returns the client side name of the
uploaded file.
Because your client & server is the same machine, your code is running
succesfully.
You should firstly save the uploaded file and then insert it into database.
As below:
this.loFile.PostedFile.SaveAs(Server.MapPath("/images/uploads/image.gif"));
....
....
fs = File.OpenRead(Server.MapPath("/images/uploads/image.gif"));
"Paul Gorman" <pgorman@satx.rr.com> wrote in message
news:0b4501c35ceb$77682610$a401280a@phx.gbl...> I am using the control type = file to perform a file
> upload. When I click on the browse button to go select
> the image I want to upload it places in the text box a
> local path (C:\images\image.jpg for example). This is
> where the image resides that I want to upload. Then I
> proceed to click on upload so that I can run through my
> code to do the upload process:
>
> string strConnection = "some connection string";
> SqlConnection oCon = new SqlConnection(strConnection);
> SqlCommand oCom = new SqlCommand();
>
> oCom.CommandText = "usp_msa_image_save_binary";
> oCom.CommandType = CommandType.StoredProcedure;
> oCom.Connection = oCon;
>
> oCon.Open();
>
> FileStream fs;
> string strFileName = this.loFile.PostedFile.FileName;
> fs = File.OpenRead(strFileName);
>
> int intCount = (int)fs.Length;
> int intSize;
>
> byte[] buffer = new byte[intCount];
> fs.Read(buffer,0,intCount);
>
> oCom.Parameters.Add("@Image", SqlDbType.Image).Value =
> buffer;
>
> oCom.Parameters.Add("@itemID", SqlDbType.VarChar,
> 30).Value = "CEH03BA401"; //Request.QueryString.Get
> ("name");
>
> if ( this.chkSmallImage.Checked )
> {
> oCom.Parameters.Add("@size", SqlDbType.Int).Value = 1;
> intSize = 1;
> }
> else
> {
> oCom.Parameters.Add("@size", SqlDbType.Int).Value = 2;
> intSize = 2;
> }
>
> oCom.ExecuteNonQuery();
> string strItemNumber = Request.QueryString.Get("name");
>
> string strUrl = "image_binary_get.aspx?itemnumber=" +
> strItemNumber + "&size=" + intSize;
>
> this.imgView.ImageUrl = strUrl;
>
>
> It continues to fail at
> fs = File.OpenRead(strFileName);
> with the error message:
> "Could not find part of the path "C:\images\image.jpg".
>
> The one thing that I can be sure of is this. When i
> attempt this process on the IIS Server where all this
> resides then it works great. As soon as I try to upload
> a file from some other computer on the network i get that
> error. Any help would be greatly appreciated. Thanks in
> advance.
>
> Paul Gorman ><>
>
>
Bülent Keskin Guest
-
Naveen K Kohli #3
Re: Uploading an Image from a web page
When you want to upload the image from a network drive, then path
"C:\Foo\Blah blah" is not local to the web server. So it will try to look
for it and then give you the error message that you are getting. You will
have to follow the netrwork drive access procudre to do it. Like
"\\MyRemoteServer\C$\Foo\Blah" assuming that you have a share created on
your network drive and your web server has permissions to access the files
there. This could be a big security problem for you.
--
Naveen K Kohli
[url]http://www.netomatix.com[/url]
"Paul Gorman" <pgorman@satx.rr.com> wrote in message
news:0b4501c35ceb$77682610$a401280a@phx.gbl...> I am using the control type = file to perform a file
> upload. When I click on the browse button to go select
> the image I want to upload it places in the text box a
> local path (C:\images\image.jpg for example). This is
> where the image resides that I want to upload. Then I
> proceed to click on upload so that I can run through my
> code to do the upload process:
>
> string strConnection = "some connection string";
> SqlConnection oCon = new SqlConnection(strConnection);
> SqlCommand oCom = new SqlCommand();
>
> oCom.CommandText = "usp_msa_image_save_binary";
> oCom.CommandType = CommandType.StoredProcedure;
> oCom.Connection = oCon;
>
> oCon.Open();
>
> FileStream fs;
> string strFileName = this.loFile.PostedFile.FileName;
> fs = File.OpenRead(strFileName);
>
> int intCount = (int)fs.Length;
> int intSize;
>
> byte[] buffer = new byte[intCount];
> fs.Read(buffer,0,intCount);
>
> oCom.Parameters.Add("@Image", SqlDbType.Image).Value =
> buffer;
>
> oCom.Parameters.Add("@itemID", SqlDbType.VarChar,
> 30).Value = "CEH03BA401"; //Request.QueryString.Get
> ("name");
>
> if ( this.chkSmallImage.Checked )
> {
> oCom.Parameters.Add("@size", SqlDbType.Int).Value = 1;
> intSize = 1;
> }
> else
> {
> oCom.Parameters.Add("@size", SqlDbType.Int).Value = 2;
> intSize = 2;
> }
>
> oCom.ExecuteNonQuery();
> string strItemNumber = Request.QueryString.Get("name");
>
> string strUrl = "image_binary_get.aspx?itemnumber=" +
> strItemNumber + "&size=" + intSize;
>
> this.imgView.ImageUrl = strUrl;
>
>
> It continues to fail at
> fs = File.OpenRead(strFileName);
> with the error message:
> "Could not find part of the path "C:\images\image.jpg".
>
> The one thing that I can be sure of is this. When i
> attempt this process on the IIS Server where all this
> resides then it works great. As soon as I try to upload
> a file from some other computer on the network i get that
> error. Any help would be greatly appreciated. Thanks in
> advance.
>
> Paul Gorman ><>
>
>
Naveen K Kohli Guest



Reply With Quote

