473,765 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\imag e.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(s trConnection);
SqlCommand oCom = new SqlCommand();

oCom.CommandTex t = "usp_msa_image_ save_binary";
oCom.CommandTyp e = CommandType.Sto redProcedure;
oCom.Connection = oCon;

oCon.Open();

FileStream fs;
string strFileName = this.loFile.Pos tedFile.FileNam e;
fs = File.OpenRead(s trFileName);

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.VarCh ar,
30).Value = "CEH03BA401 "; //Request.QuerySt ring.Get
("name");

if ( this.chkSmallIm age.Checked )
{
oCom.Parameters .Add("@size", SqlDbType.Int). Value = 1;
intSize = 1;
}
else
{
oCom.Parameters .Add("@size", SqlDbType.Int). Value = 2;
intSize = 2;
}

oCom.ExecuteNon Query();
string strItemNumber = Request.QuerySt ring.Get("name" );

string strUrl = "image_binary_g et.aspx?itemnum ber=" +
strItemNumber + "&size=" + intSize;

this.imgView.Im ageUrl = strUrl;
It continues to fail at
fs = File.OpenRead(s trFileName);
with the error message:
"Could not find part of the path "C:\images\imag e.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 ><>
Nov 17 '05 #1
2 1875
this.loFile.Pos tedFile.FileNam e 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.Pos tedFile.SaveAs( Server.MapPath( "/images/uploads/image.gif"));
....
....
fs = File.OpenRead(S erver.MapPath("/images/uploads/image.gif"));

"Paul Gorman" <pg*****@satx.r r.com> wrote in message
news:0b******** *************** *****@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\imag e.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(s trConnection);
SqlCommand oCom = new SqlCommand();

oCom.CommandTex t = "usp_msa_image_ save_binary";
oCom.CommandTyp e = CommandType.Sto redProcedure;
oCom.Connection = oCon;

oCon.Open();

FileStream fs;
string strFileName = this.loFile.Pos tedFile.FileNam e;
fs = File.OpenRead(s trFileName);

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.VarCh ar,
30).Value = "CEH03BA401 "; //Request.QuerySt ring.Get
("name");

if ( this.chkSmallIm age.Checked )
{
oCom.Parameters .Add("@size", SqlDbType.Int). Value = 1;
intSize = 1;
}
else
{
oCom.Parameters .Add("@size", SqlDbType.Int). Value = 2;
intSize = 2;
}

oCom.ExecuteNon Query();
string strItemNumber = Request.QuerySt ring.Get("name" );

string strUrl = "image_binary_g et.aspx?itemnum ber=" +
strItemNumber + "&size=" + intSize;

this.imgView.Im ageUrl = strUrl;
It continues to fail at
fs = File.OpenRead(s trFileName);
with the error message:
"Could not find part of the path "C:\images\imag e.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 ><>

Nov 17 '05 #2
When you want to upload the image from a network drive, then path
"C:\Foo\Bla h 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
"\\MyRemoteServ er\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
http://www.netomatix.com
"Paul Gorman" <pg*****@satx.r r.com> wrote in message
news:0b******** *************** *****@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\imag e.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(s trConnection);
SqlCommand oCom = new SqlCommand();

oCom.CommandTex t = "usp_msa_image_ save_binary";
oCom.CommandTyp e = CommandType.Sto redProcedure;
oCom.Connection = oCon;

oCon.Open();

FileStream fs;
string strFileName = this.loFile.Pos tedFile.FileNam e;
fs = File.OpenRead(s trFileName);

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.VarCh ar,
30).Value = "CEH03BA401 "; //Request.QuerySt ring.Get
("name");

if ( this.chkSmallIm age.Checked )
{
oCom.Parameters .Add("@size", SqlDbType.Int). Value = 1;
intSize = 1;
}
else
{
oCom.Parameters .Add("@size", SqlDbType.Int). Value = 2;
intSize = 2;
}

oCom.ExecuteNon Query();
string strItemNumber = Request.QuerySt ring.Get("name" );

string strUrl = "image_binary_g et.aspx?itemnum ber=" +
strItemNumber + "&size=" + intSize;

this.imgView.Im ageUrl = strUrl;
It continues to fail at
fs = File.OpenRead(s trFileName);
with the error message:
"Could not find part of the path "C:\images\imag e.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 ><>

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
17482
by: ok | last post by:
Hello, Q: How do I get image width and height before uploading an image? This because, I want to restrict people uploading huge files. Thanks in advance
10
7404
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't recommend storing the image to the filesystem and only keeping a pointer to that in the table. I want to dump the image to a table. My code dumps the data into the table, however, I get the following error when trying to view the image "the image ......
5
3114
by: Grant Harmeyer | last post by:
I have an application that uses FreeTextBox 2.0 (http://www.freetextbox.com). FreeTextBox is a rich text editor that behaves similarly to MS Word. The FreeTextBox control has a button to insert images (just as you would with MS Word) and it works beautifully. The problem is that when you include an image with the rich text editor, the image path is the local path on the client. I have written a method that examines the text for <img> tags,...
3
3211
by: Kumarasamy.Mani | last post by:
Hi all, I'm having the following issue in image preview. I'm having an File Upload option in my web page, there i'm having one more option preview. When the user is uploading the image using the input box, i need to show preview of the image. When i'm using in MSIE it's working fine but in Netscape Browser's it's not working at all. This is my logic in Javascript
3
2315
by: Gavin | last post by:
I need some help, I need the code to allow people that visit my website to be able to upload pictures to a file on my web server. I have been able to get close, but not quite there yet. Set fso = createobject("scripting.filesystemobject") Set act = fso.CreateTextFile(server.mappath("test.jpg"), true) act.WriteLine act.Close The above code will create the file but will not write any data in it. Below
1
2080
by: wenqiang7 | last post by:
I am encountering a very strang problem with file uploading in my ASP.Net page. When we try to upload certain file, we'll get an error msg of "Cannot find server or DNS Error". We are running on Win2003, IIS, ASP.Net 1.1. The page works fine if running from localhost. It only has problem when accessed from a domain name.
4
1672
by: | last post by:
Can someone offer or point me to some sample code or advice on how to upload a document from a web page and store it into a SQL Server image field? And then reverse the process and serve up the file from the database when requested through a web page... Thanks. Jerry
1
2588
by: Kunal Nandi | last post by:
can any one give me the code for uploading and retriving image using Blob, with jsp at front end and oracle8i at the back end ??????? i have tried this using long raw datatype i was able to upload it, but while retriving first i have to create a temporary image file for that. and then i m able to retirve it on the web page, but i want it to be directly retrived on the web page.
1
2076
by: thulaseeram | last post by:
I am using iframe to store uploaded images, it is uploading fine in IE but it is not happening in firefox means first time it is uploading image if i try to upload second image it is not calling even java script function and not uploading the image in firefox. I am using this code in the button onclick event "attach_frame.upload();" here attach_frame is the iframe name and id to which the uploaded image should add. please can any one help me to...
1
2127
pezholio
by: pezholio | last post by:
Hi, It seems that every time I put together a new script to upload a file I always have problems, here's the latest one: I've got a form with two file input fields, when I submit the form, everything goes OK, but the files don't upload, the permissions on the folders are fine and dandy (Both 777). Here's my code: if(is_uploaded_file($_FILES)){ $target_path = "/home/default/ratemyplace.org.uk/user/htdocs/newsite/images/premimages/";
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7378
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.