 |
| .NET Web Services Discussions about .NET XML Web Service technologies including ASMX files, WSDL and SOAP. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the .NET Web Services 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
|
|
|
|

February 5th, 2004, 02:03 PM
|
|
Registered User
|
|
Join Date: Jan 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
file upload and download
I would like to create a .net web service for downloading and uploading a excel or text file.
How to do that? Is there any sample code / article available?
Thanks
Thanks and regards
Siva
|
|

February 5th, 2004, 02:36 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
What do you mean? Do you want a user to upload/download the file?
|
|

February 6th, 2004, 05:39 AM
|
|
Registered User
|
|
Join Date: Jan 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yes, you are right. Using the Web Service, the user should be able to upload and download file. How to do that?
Thanks and regards
Siva
|
|

February 6th, 2004, 01:23 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
You don't. That's not what web services are for. Web services are designed for the purposes of providing data over HTTP using XML. This data is used, or "consumed" by other applications. Web services are designed as a end use interface. You need to create a web form to do this. Try this google search for help on how to upload files using ASPX web forms.
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

February 15th, 2004, 08:13 AM
|
|
Registered User
|
|
Join Date: Feb 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
No.It's very easy to upload or download any document with web services. Here is a sample example :
This is for web services :
<WebMethod()> PublicFunction UploadFile(ByVal fs()As Byte,ByVal FlName As String)As String
Try
Dim m As New MemoryStream(fs)
Dim f As New FileStream("c:\tempUploaded\" & FlName, FileMode.Create)
m.WriteTo(f)
m.Close()
f.Close()
f = Nothing
m = Nothing
Return "File Uploaded"
Catch ex As Exception
Return ex.Message
End Try
End Function
Note: You must import System.IO
--------------------------------------
This is for your asp.net file (or win app)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim f As System.IO.File
Dim fs As System.IO.FileStream
Dim o As New localhost.Service1()
'file to upload
fs = f.Open("c:\upload.pdf", IO.FileMode.Open, IO.FileAccess.Read)
Dim b(fs.Length - 1) As Byte
fs.Read(b, 0, fs.Length)
MsgBox(o.UploadFile(b, "upload.pdf"))
f = Nothing
fs.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
|
|

February 16th, 2004, 12:27 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
okantekeli,
Right, so you have confirmed my point. The web service doesn't provide the capability to upload/download the file. You must create a user interface (ASP.net or winforms application) that provides the capability to deal with the user's local file(s) and then could use the web service to take the file as a byte stream and do whatever it needs with it. In the case of an ASP.net web application, you actually need to upload/download the file in the context of an HTTP connection (between the server and the browser). In the case of a winforms application, you are dealing with the file locally and thus you aren't actually doing any upload/download per se. What you do with the application internally is irrelevant. In the case of your example, you have a web service that handles a byte stream and dumps it to a file and you have a winform app that handles a file locally and uses the web service. The point remains that the web service itself is not providing the "upload/download" capability.
This discussion is really a matter of semantics. The real question that should be posed is: What is the ultimate goal regarding the original post? Is the desired result a web interface to upload/download a file? If so, then okantekeli's suggestion can be implemented as described. The web interface is doing the uploading and downloading, it just happens to use a web service instead of a local file IO.
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

February 19th, 2005, 04:17 PM
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This works great on my local machine; how can you use another web server with this. I'm using a VB.NET app to send the file and can't figure out how to specify another web server other than local.
Thanks!
|
|
 |