Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 21st, 2007, 06:34 AM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

  #2 (permalink)  
Old March 21st, 2007, 06:49 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
================================================== =========
  #3 (permalink)  
Old March 21st, 2007, 07:23 AM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

  #4 (permalink)  
Old March 21st, 2007, 07:26 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
================================================== =========
  #5 (permalink)  
Old March 21st, 2007, 08:11 AM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear friend,

btw, what is AJAX ? how to do it with AJAX ?

sorry , that i do not know AJAX.

Tks,
hendy

  #6 (permalink)  
Old March 21st, 2007, 08:14 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
================================================== =========
  #7 (permalink)  
Old March 21st, 2007, 08:23 AM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

  #8 (permalink)  
Old March 21st, 2007, 09:05 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
================================================== =========
  #9 (permalink)  
Old March 21st, 2007, 09:31 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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
================================================== =========
  #10 (permalink)  
Old March 21st, 2007, 10:41 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to save a file on client side gauravawas ASP.NET 2.0 Professional 0 April 23rd, 2008 07:55 AM
How can I save Crystal Report File to Image File? Muhammad Akbar Crystal Reports 0 July 10th, 2007 05:33 PM
How to create and Save an Xml file at client side. kiranvsamuel XML 1 June 30th, 2006 05:26 AM
save a file on client machine sumsin ASP.NET 1.0 and 1.1 Basics 1 March 30th, 2005 05:52 PM
Open file and save it? tpsmith78 VS.NET 2002/2003 0 January 28th, 2004 12:30 PM



All times are GMT -4. The time now is 10:39 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.