File upload on Asp.net

hell experts

I am trying to pass an asp.net application a string to a path for a text document on a clients computer and i would like to upload that file automatically

however using the simple FileInfo just points to the path of the document at the server side

the aim is to upload a document dynamically in code as soon as its generated
samelaminAsked:
Who is Participating?
 
MistralolCommented:

No there are two half's There is the server which is reciving the file and the client which is sending the file.

The server cannot request a client to send a specific file (this is the original issue). The file request must initiated by the client. So the client sends the file though the web service. I just thought the web service would be easyier for you to use. Since it will be almost like calling what appears to be a local function from the client (which is really executed on the server side) with the contents of the file and any other information that is required.

So if you have a function in the web service call void NewFile(byte[] data, string FileName);

On the client win forms app you can read the contents into a a byte[] array
then call the function like this TheService.NewFile(array, "The File Name.txt");

So the client calls the function on the server where it is executed with the contents of the file.

If this is getting too complex i would suggest you drop back to the FileUploadControl. Effectivly what you are doing is replacing the web browser with the winforms apps. So if you truly wanted to automate it you could connect to the winforms app from the server and request it send you the file. This would make it yet more complex however (if you were planning on doing this you could completly loose the web serivce / web server completly)





0
 
Amandeep Singh BhullarCommented:
Hi

you cannot upload a file without using file upload control(HTTP Upload).

Can give you a idea
1. Place a Hidden File Upload Control on page
2. After the file path is generated, assign the path to File Upload Control
3. Trigger the file Upload
For this you can user AJAX
Check sample Upload control: http://en.fileuploadajax.subgurim.net/

Alternatively you can use FTP upload,
Check example
http://www.devasp.net/net/articles/display/280.html
0
 
masterpassCommented:
From what I know, its not possible .... the path will just contain the physical drive path with the file details .. you can never access the file from the client if only the file path is given. security features are in place for the clients which will prevent you from accessing ....

Alternative way is to have the client upload the files he needs which is more secure
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
samelaminAuthor Commented:
yes i thought of that but unfortunatly its supposed to occur automatically
and i tried assigning the path but i keep getting errors

maybe the syntax is wrong, how do you assign a path to file upload controlin code behind?
0
 
masterpassCommented:
you cannot assign the path to the fileupload from the code behind ... I think you are getting confused .. When the user tries to upload the file, you can just get the file by

FileUpload1.SaveAs("pathtosave");

note that pathtosave is the path in the server
0
 
samelaminAuthor Commented:
Yes that i understand that masterpass

so what your saying is that there is no way whatsoever to pass a path to upload the file to the server without the need to press a button?
0
 
masterpassCommented:
YES, that is correct.... you cannot upload the file unless uploaded by the client. The server CANNOT control the files inside the client if the path is given ....
0
 
samelaminAuthor Commented:
ok can it open and read the file?

beause i can then just copy the contents of the file to the server using Fstream
0
 
samelaminAuthor Commented:
or maybe create a temp file in C and email it to the server?

can this be done as an alternative?
0
 
masterpassCommented:
see if your file is in the client, you can only read the file content using HTTP protocol. For that you will have to use the file upload control. I don't think there is an alternative for this !!!
0
 
samelaminAuthor Commented:
ok son in summary i need to use File Control and there is no way to pass or assign the path to it, the user NEEDS to browse for the file themselves

0
 
samelaminAuthor Commented:
*Correction
ok so in summary i need to use File Control and there is no way to pass or assign the path to it, the user NEEDS to browse for the file themselves
0
 
MistralolCommented:

Yes you need to use the file upload control.

There is another altenative. But will require you create an ocx / active x control and require that the end user is using ie (with security ajusted correctly) you can then embed this in a web page and it can read the file and post it to the server. Though its requires a lot of work todo this and will probably break everytime ie is updated i would really recommend not doing it.

Another altenative would be to write a small client and install it on the end users computer. This would then upload the file automatically to the website by a web service method.

A 3rd would work if the machine is local (on the same network as the server) where it could access a shared folder across the network to get the file from the client machine.

The function you are really asking for is for anyone who makes a website to be able to see content on the *any* visitors computer. This is why it is so protected.

0
 
samelaminAuthor Commented:
I see what you mean
ok from those options i think the 2nd seems the most effecient

how do i go about writing this client software?
is it a windows form application?

0
 
MistralolCommented:

Yes its a windows form application.

Before you do the windows form application you will probably need to make the web service function.
You should be able to add a file ending in asmx to the project (there should be a template for it)

Once its added it should have a sample "Hello, World" function inside. You can just change this to take a username / password / byte[] data and any other information you want. This is what you want todo on the server side of things.

You then probably also want to create a forms project. Once this is created you can add a web reference this should be to the web server where your "service" is running the url should be pointed at the file you added ending in .asmx you can then create and instance of the sevice and call the function as if it is local (its actually doing the web request for you) passing the information you need eg the filecontent.

I would strongly recommand that you also implement some sort of security even if its checking by client ip address if the project is on a public web server you need to know that anyone can also call the same function.

Everything you need to know is located at http://msdn.microsoft.com/en-us/library/ms972326.aspx




0
 
samelaminAuthor Commented:
alright thanks ill look into it
0
 
samelaminAuthor Commented:
ok i have a few questions

the Web service, is it whats doing the uploading for me? because why else would you need to give it credentials, i already have an asp.net app that uploads

and i heard that i need to convert the text file to a binary stream so the form is basically calling the webservice which will convert the text file to a binary stream

is that possible?
0
 
samelaminAuthor Commented:
what do you mean by lose the web server ?

also i dont mind writing a windows form app to run on the client side, and then writing the text file to a byte array and pass it to the sewrver where it would be converted back to text file

that sounds simple enough right?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.