 |
| ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 21st, 2007, 06:34 AM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
open image file from client then save to server
Dear friend,
i'm a ASP .NET beginner...
as we know that ASP .NET has client side and server side...
btw, how we can open a file from C:\Jaguar.jpg (open then pass it as byte of array)...and from this byte of array, how we can save to Server.MapPath folder (such as "Images\jaguar.jpg")..
i use File.Open
but it can not open C:\jaguar.jpg...
Thank you,
hendy
|
|

March 21st, 2007, 06:49 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
You have to use the HTML File Upload control to do this.
http://www.4guysfromrolla.com/webtech/091201-1.shtml
Be aware that by doing this, the worker process loads the ENTIRE file into memory and, unfortunately, it will never release most of that memory once the file is uploaded. By default, the worker process will consumer 80% of available server memory before it recycles itself so, unless you write an HTTPModule that will stream files to disk, you will need to monitor this and know that there is a potential for your worker process to crash and take down your application while it recycles itself.
This was fixed in 2.0 as is documented here:
http://aspnetresources.com/articles/...e_uploads.aspx
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
|
|

March 21st, 2007, 07:23 AM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
dear friend,
yes, i tried HTML File Upload control also...
but it has some shortcomings :
1. i can not find the control's event after we select an image file from client (e.g. c:\jaguar.jpg), i need the event to put my source code to automatically get the InputStream and save it to Server.MapPath("Images\jaguar.jpg")....
all the samples only suggest that we use another button to do HttpPosted.inputstream saving to server....but it means it does not triggered automatically after we select a file..
for comparison, perhaps you know how easy it's done if we use File Dialog control in windows application...there's event after we select a file in File Dialog ,right ?
do you know how to trigger the event ?
Thanks,
hendy
|
|

March 21st, 2007, 07:26 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
There is no event exposed (that i know of) in the file upload control that will automatically upload the file once it has been selected, it requires a post back to the server OR you need to use some sort of AJAX to facilitate this.
(I also do not think that there is an event raised on the server when you click the browse button of the File Upload control)
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
|
|

March 21st, 2007, 08:11 AM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Dear friend,
btw, what is AJAX ? how to do it with AJAX ?
sorry , that i do not know AJAX.
Tks,
hendy
|
|

March 21st, 2007, 08:14 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
AJAX == Asyncronous Javascript And XML
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
|
|

March 21st, 2007, 08:23 AM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i'm thinking of other way:
1. we make a string of javascript code.
2. then we use RegisterStartupScript(a string of javascript code)..
3. JavaScript code contains :
a. click the Htmlinput file control.
b. then we save the Htmlinputfile.value to a text box (txtFileName.Value) ..
it contains the full path of the image file that we browse and select..
4. after RegisterStartupScript, we add some code like this :
Dim s As Stream = File.OpenRead(txtFileName.Value)
Dim buffer(s.Length) As Byte
s.Read(buffer, 0, CType(s.Length, Integer))
Dim len As Integer = CType(s.Length, Integer)
s.Close()
Dim fs As FileStream = New FileStream(Server.MapPath(Request.ApplicationPath) & "\Images\HORE.jpg", FileMode.Create)
fs.Write(buffer, 0, len)
fs.Close()
but it returns error when we do File.OpenRead..
do you know other way to open image file in client side in order to get its array of byte (buffer) ??
Thank you.
hendy
|
|

March 21st, 2007, 09:05 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
That code should throw an error. The code above is executed in the context of the server, not the client, so calling File.OpenRead(txtFileName.Value) is referencing a value on the client, not the server.
Unfortunately, I think you are a bit confused. You are going to be able to do this 1 of 2 ways.
1. Click the control and the user selects the image; they post the form and you grab a reference to the PostedFile.InputStream to save the file somewhere on the server disk.
2. Use JavaScript/AJAX to upload the file to the server client side.
Essentially what you are trying to do, based upon your last post, is the AJAX method. You want the client to read the image file into a byte array and then you want the server to handle the actual saving of the image.
Investigate AJAX File Uploading.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
|
|

March 21st, 2007, 09:31 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
hi there..
i think this is easier than you think...
you have the htmlupload control.. you don't need any java script (unless you want to have an update status bar)...
you have a button in your page that submit the file (the control will not submit it by itself)..
in the code for the button you do something like this:
Code:
Dim FileName As String = System.IO.Path.GetFileName(Me.fileuploadcontrol.PostedFile.FileName)
Dim DestPath As String = Server.MapPath("yourfolderdestination") & "\"
'the next line will do the upload
Me.fileuploadcontrol.PostedFile.SaveAs(DestPath & "\" & filename)
just remember to change the bold text with your own...
you can do this with ajax to avoid a full page refresh, just put the button and the htmlcontrol inside an update panel...
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
|
|

March 21st, 2007, 10:41 PM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Dear all,
Thanks for your kind answers..it's a great contribution...
however could you recommend a good site/link
where i can start learning about AJAX ?
Thank you,
hendy
|
|
 |